java

java - Java - Programmation

Marsh Posté le 28-09-2008 à 17:30:34    

Bonjour,  
 
 je susi débutant et e n arrive pas a rectifier mon erreure ...
svp une petite aide ^^
 
 
 
public class Exercice2_11 {
 
   public static java.util.Scanner scanner = new java.util.Scanner(System.in);
 
      public static void main(String[] args) {
 
      int premierNombre, secondNombre, reponseEleve, deuxiemeChance, troisiemeChance, reponseCorrecte;
 
         premierNombre = unEntierAuHasardEntre (0, 10);  
         secondNombre = unEntierAuHasardEntre (0, 10);
 
         System.out.println ("Calculez : " );
 
         System.out.println ( premierNombre * secondNombre + "=" + " ... " );
         reponseEleve = scanner.nextInt();
         
      if (reponseEleve = reponseCorrecte )  
         System.out.println ("Très bien" );
      else {
         System.out.println ("La réponse est fausse!" );
         System.out.println ("Deuxième chance :" );  
      deuxiemeChance = scanner.nextInt();
         if (deuxiemeChance = reponseCorrecte )  
         System.out.println ("Très bien" );
            else{  
            System.out.println ("La réponse est fausse!" );
            System.out.println ("Vous avez le droit à une dernière chance :" );
            troisiemeChance = scanner.nextInt();
            if (troisiemeChance = reponseCorrecte)
            System.out.println ("Très bien" );
               else
                  System.out.println ("La réponse est fausse!" );
                  System.out.println ("La réponse correcte était :" + reponseCorrecte);
               
               
            }
         }
      }
 
   public static int unEntierAuHasardEntre (int valeurMinimale, int valeurMaximale){
      double nombreRéel;
      int résultat;
 
      nombreRéel = Math.random();
      résultat = (int) (nombreRéel * (valeurMaximale - valeurMinimale + 1))
                        + valeurMinimale;
      return résultat;
   }
   }
 
 
 
 
 
 
 
 
Message d erreur :
 
ÏÏ«Ï ----jGRASP exec: javac -g C:\Documents and Settings\Ouariors\Mes documents\Fayçal école\Algorithmique\Fiche 2 26.09.2008\Exercice2_11.java
ÏϧÏ
ϼ§ÏExercice2_11.java:18: incompatible types
ÏϧÏfound   : int
ÏϧÏrequired: boolean
ÏÏ§Ï            if (reponseEleve = reponseCorrecte )  
ÏÏ§Ï                             ^
ϼ§ÏExercice2_11.java:24: incompatible types
ÏϧÏfound   : int
ÏϧÏrequired: boolean
ÏÏ§Ï                    if (deuxiemeChance = reponseCorrecte )  
ÏÏ§Ï                                       ^
ϼ§ÏExercice2_11.java:30: incompatible types
ÏϧÏfound   : int
ÏϧÏrequired: boolean
ÏÏ§Ï                            if (troisiemeChance = reponseCorrecte)
ÏÏ§Ï                                                ^
ϼ§ÏExercice2_11.java:45: possible loss of precision
ÏϧÏfound   : double
ÏϧÏrequired: int
ÏÏ§Ï            nombreRéel = Math.random();
ÏÏ§Ï                                    ^
ÏϧÏ4 errors
ÏϧÏ
ÏÏ§Ï ----jGRASP wedge2: exit code for process is 1.
ÏÏ©Ï ----jGRASP: operation complete.
 
 
Merci


---------------
fayss
Reply

Marsh Posté le 28-09-2008 à 17:30:34   

Reply

Marsh Posté le 28-09-2008 à 17:39:32    

java


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
Reply

Marsh Posté le 28-09-2008 à 22:15:35    

Salut Fayçal,
On écrit pas if (troisiemeChance = reponseCorrecte)
on écrit plutôt if (troisiemeChance == reponseCorrecte)
 
Quand tu fais un "if" et que tu veux comparer deux valeurs, tu utilises le "=="
 
ex. : if (a==1)
 
Je t'explique :
a==1 renvoie un booléen (qui contient soit vrai soit faux. Si a est égal à 1, le booléen contiendra vrai)
 
Et le "if" demande un booléen entre parenthèses...
 
@+


---------------
Site de rencontre
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed