IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

avec Java Discussion :

Maximum et minimum


Sujet :

avec Java

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Décembre 2008
    Messages : 15
    Points : 13
    Points
    13
    Par défaut Maximum et minimum
    Bonjour,

    J'ai créer le programme suivant qui permet d'Afficher les notes de 10 étudiants et d'en calculer la moyenne. Jusqu'ici tout va bien, par contre j'Aimerais être capable de faire afficher la note maximum et la note minimum des 10 notes qui ont été affichés préalablement et là c'est un gros blanc ... Voici mon programme :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    public class blablabla {
     
      public static void main(String[] args) {
     
      	int a = 1 + (int)(100*Math.random());
      	int b = 1 + (int)(100*Math.random());
      	int c = 1 + (int)(100*Math.random());
      	int d = 1 + (int)(100*Math.random());
      	int e = 1 + (int)(100*Math.random());
      	int f = 1 + (int)(100*Math.random());
      	int g = 1 + (int)(100*Math.random());
      	int h = 1 + (int)(100*Math.random());
      	int i = 1 + (int)(100*Math.random());
      	int j= 1 + (int)(100*Math.random());
      	int moy = (a+b+c+d+e+f+h+i+j) / 10;
      	int max = //incapable de trouver une solution//
      	int min = //idem//
     
     
     
        System.out.println("Notes1 = " + a + "%");
        System.out.println("Notes1 = " + b + "%");
        System.out.println("Notes1 = " + c + "%");
        System.out.println("Notes1 = " + d + "%");
        System.out.println("Notes1 = " + e + "%");
        System.out.println("Notes1 = " + f + "%");
        System.out.println("Notes1 = " + g + "%");
        System.out.println("Notes1 = " + h + "%");
        System.out.println("Notes1 = " + i + "%");
        System.out.println("Notes1 = " + j + "%");
        System.out.println("La moyenne du groupe = " + moy + "%");
        System.out.println("La note la plus forte = " + max + "%");
        System.out.println("La note la plus faible = " + min + "%");
     
     
      }
     
    }
    Merci beaucoup, vous m'êtes d'une précieuse aide dans ce début de carrière en programmation

    Jonathan

  2. #2
    Membre expérimenté Avatar de Ivelios
    Homme Profil pro
    Développeur Java
    Inscrit en
    Juillet 2008
    Messages
    1 031
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 031
    Points : 1 540
    Points
    1 540
    Par défaut
    Il te suffit de stocker tes notes dans un tableau ou une liste.
    Ensuite tu parcours ton tableau, tu compares les valeurs et tu récupère le minimum et le maximum.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    public class blablabla {
     
      public static void main(String[] args) {
     
          int[] notes = new int[10];
     
          //Remplissage
          for(int i=0;i<notes.length;i++){
              notes[i]= 1 + (int)(100*Math.random());
          }
     
          int max = notes[0];
          int min = notes[0];
          int moy = notes[0];
          for(int i=1;i<notes.length;i++){
              if(notes[i]>max) max = notes[i];        
              if(notes[i]<min) min = notes[i];
              moy +=notes[i];
          }
     
          moy = moy /10;
     
          for(int i=0;i<notes.length;i++){
               System.out.println("Notes1 = " + notes[i] + "%");
          }
     
        System.out.println("La moyenne du groupe = " + moy + "%");
        System.out.println("La note la plus forte = " + max + "%");
        System.out.println("La note la plus faible = " + min + "%");
     
     
      }
     
    }
    Il était une fois [...] Et ils vécurent heureux et eurent beaucoup d'enfants!

  3. #3
    Membre confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2008
    Messages
    328
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Mexique

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juin 2008
    Messages : 328
    Points : 459
    Points
    459
    Par défaut
    Salut,

    En mettant effectivement les notes dans un tableau,
    puis en triant ce tableau, la 1ère note est la note mini, la dernière est la note maxi.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
     
    import java.util.Arrays;
     
        public class Blablabla
       {
           public static void main(String[] args)
          {
             //String tabNotes = new String(10);
     
             int a = 1 + (int)(100*Math.random());
             int b = 1 + (int)(100*Math.random());
             int c = 1 + (int)(100*Math.random());
             int d = 1 + (int)(100*Math.random());
             int e = 1 + (int)(100*Math.random());
             int f = 1 + (int)(100*Math.random());
             int g = 1 + (int)(100*Math.random());
             int h = 1 + (int)(100*Math.random());
             int i = 1 + (int)(100*Math.random());
             int j= 1 + (int)(100*Math.random());
             int moy = (a+b+c+d+e+f+h+i+j) / 10;
             // mettre les notes obtenues dans un tableau
             int tabNotes[] = {a, b, c, d, e, f, g, h, i, j};
     
             System.out.println("Note1 = " + a);
             System.out.println("Note2 = " + b);
             System.out.println("Note3 = " + c);
             System.out.println("Note4 = " + d);
             System.out.println("Note5 = " + e);
             System.out.println("Note6 = " + f);
             System.out.println("Note7 = " + g);
             System.out.println("Note8 = " + h);
             System.out.println("Note9 = " + i);
             System.out.println("Note10 = " + j);
             System.out.println("La moyenne du groupe = " + moy);
             //System.out.println("La note la plus forte = " + max + "%");
             //System.out.println("La note la plus faible = " + min + "%");
                   // tri du tableau:
             Arrays.sort(tabNotes); // import java.util.Arrays;
             int mini = tabNotes[0];
             int maxi = tabNotes[9];
             System.out.println("La note mini est: " + mini);
             System.out.println("La note maxi est: " + maxi);
          }
       }
    Cordialement,

    Dan

Discussions similaires

  1. maximum et minimum locaux
    Par slaima15 dans le forum Signal
    Réponses: 2
    Dernier message: 22/09/2009, 17h14
  2. Maximum ou minimum entre plusieurs colonnes
    Par theworst dans le forum SQL
    Réponses: 2
    Dernier message: 04/03/2009, 10h34
  3. Permutations, maximum et minimum des chiffres d'un entier
    Par JetliMohamed dans le forum Pascal
    Réponses: 14
    Dernier message: 29/01/2008, 22h20
  4. Réponses: 6
    Dernier message: 02/04/2007, 14h20

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo