Problème compilation java
Absot
Messages postés
819
Statut
Membre
-
hamed01 Messages postés 212 Statut Membre -
hamed01 Messages postés 212 Statut Membre -
Bonjour, je suis en train de faire une petite calculette toute simple en java en console avec éclipse mais quand je compile, il me dit qua ma variable "choix" n'est pas résolu et je me demande pourquoi.. :/
Je vous montre mon code:
--------------------------------------------------------------------------
import java.util.Scanner;
public class sdz1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner lire = new Scanner (System.in);
do{
double premier;
double second;
int choix;
double res;
System.out.println("Saisissez un premier nombre");
premier = lire.nextDouble();
System.out.println("Saisissez un deuxième nombre");
second = lire.nextDouble();
System.out.print("1 pour ajouter /n" +
"2 pour soustraire /n" +
"3 pour multiplier /n" +
"4 pour diviser /n" +
"5 pour quitter");
choix = lire.next();
switch (choix) {
case '1':
res = (premier+second);
System.out.println("Le résultat est " + res);
break;
case '2':
res = (premier-second);
System.out.println("Le résultat est " + res);
break;
case '3':
res = (premier*second);
System.out.println("Le résultat est " + res);
break;
case '4':
res = (premier/second);
System.out.println("Le résultat est " + res);
break;
Default:
System.out.println("Erreur de programmation");
}
}
while ( (choix ='1') or (choix ='2') or (choix ='3') or (choix ='4') );
}
}
-------------------------------------------------------------------------------
Vous pouvez m'aider svp?
Je vous montre mon code:
--------------------------------------------------------------------------
import java.util.Scanner;
public class sdz1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner lire = new Scanner (System.in);
do{
double premier;
double second;
int choix;
double res;
System.out.println("Saisissez un premier nombre");
premier = lire.nextDouble();
System.out.println("Saisissez un deuxième nombre");
second = lire.nextDouble();
System.out.print("1 pour ajouter /n" +
"2 pour soustraire /n" +
"3 pour multiplier /n" +
"4 pour diviser /n" +
"5 pour quitter");
choix = lire.next();
switch (choix) {
case '1':
res = (premier+second);
System.out.println("Le résultat est " + res);
break;
case '2':
res = (premier-second);
System.out.println("Le résultat est " + res);
break;
case '3':
res = (premier*second);
System.out.println("Le résultat est " + res);
break;
case '4':
res = (premier/second);
System.out.println("Le résultat est " + res);
break;
Default:
System.out.println("Erreur de programmation");
}
}
while ( (choix ='1') or (choix ='2') or (choix ='3') or (choix ='4') );
}
}
-------------------------------------------------------------------------------
Vous pouvez m'aider svp?
A voir également:
- Problème compilation java
- Jeux java itel - Télécharger - Jeux vidéo
- Waptrick java football - Télécharger - Jeux vidéo
- Waptrick java voiture - Télécharger - Jeux vidéo
- Eclipse java - Télécharger - Langages
- Java apk - Télécharger - Langages
8 réponses
while ( (choix ='1') or (choix ='2') or (choix ='3') or (choix ='4') );
c'est plutot:
while ( (choix ==1) || (choix ==2) || (choix ==3) || (choix ==4) );
c'est plutot:
while ( (choix ==1) || (choix ==2) || (choix ==3) || (choix ==4) );
Je viens de remplacer choix = lire.next(); par choix = lire.nextInt(); ...
J'ai moins d'erreur mais j'en ai toujours, voilà ce que j'ai:
------------------------------------------------------
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
choix cannot be resolved
Syntax error, insert ") ;" to complete DoStatement
choix cannot be resolved
Syntax error, insert ";" to complete Statement
choix cannot be resolved
Syntax error on token ")", . expected
choix cannot be resolved
at sdz1.main(sdz1.java:55)
---------------------------------------------------------
La ligne "at sdz1.main(sdz1.java:55)" veut dire que j'ai une erreur à la ligne 55?
J'ai commencé aujourd'hui avec éclipse.. ^^
J'ai moins d'erreur mais j'en ai toujours, voilà ce que j'ai:
------------------------------------------------------
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
choix cannot be resolved
Syntax error, insert ") ;" to complete DoStatement
choix cannot be resolved
Syntax error, insert ";" to complete Statement
choix cannot be resolved
Syntax error on token ")", . expected
choix cannot be resolved
at sdz1.main(sdz1.java:55)
---------------------------------------------------------
La ligne "at sdz1.main(sdz1.java:55)" veut dire que j'ai une erreur à la ligne 55?
J'ai commencé aujourd'hui avec éclipse.. ^^
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
Je viens de remplacer mes ='1' par ==1...
Voici ce que l'on me dit:
------------------------------------------------------------------
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
choix cannot be resolved
Syntax error, insert ") ;" to complete DoStatement
choix cannot be resolved
Syntax error, insert ";" to complete Statement
choix cannot be resolved
Syntax error on token ")", . expected
choix cannot be resolved
at sdz1.main(sdz1.java:55)
---------------------------------------------------------------------
La ligne 55 est la ligne avec le while...
Voici ce que l'on me dit:
------------------------------------------------------------------
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
choix cannot be resolved
Syntax error, insert ") ;" to complete DoStatement
choix cannot be resolved
Syntax error, insert ";" to complete Statement
choix cannot be resolved
Syntax error on token ")", . expected
choix cannot be resolved
at sdz1.main(sdz1.java:55)
---------------------------------------------------------------------
La ligne 55 est la ligne avec le while...
t'a remplacé les "or" par || comme suit :
while ( (choix ==1) || (choix ==2) || (choix ==3) || (choix ==4) );
(j'ai jamais rencontré de Or dans java moi...)
while ( (choix ==1) || (choix ==2) || (choix ==3) || (choix ==4) );
(j'ai jamais rencontré de Or dans java moi...)
Oui je les ai remplacé et j'ai toujours des erreurs...
Mon code:
----------------------------------------------------------------------
import java.util.Scanner;
public class sdz1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner lire = new Scanner (System.in);
do{
double premier;
double second;
int choix;
double res;
System.out.println("Saisissez un premier nombre");
premier = lire.nextDouble();
System.out.println("Saisissez un deuxième nombre");
second = lire.nextDouble();
System.out.print("1 pour ajouter /n" +
"2 pour soustraire /n" +
"3 pour multiplier /n" +
"4 pour diviser /n" +
"5 pour quitter");
choix = lire.nextInt();
switch (choix){
case '1':
res = (premier+second);
System.out.println("Le résultat est " + res);
break;
case '2':
res = (premier-second);
System.out.println("Le résultat est " + res);
break;
case '3':
res = (premier*second);
System.out.println("Le résultat est " + res);
break;
case '4':
res = (premier/second);
System.out.println("Le résultat est " + res);
break;
Default:
System.out.println("Erreur de programmation");
}
}
while ( (choix ==1) || (choix ==2) || (choix ==3) || (choix ==4) );
}
}
-----------------------------------------------------------------------
Et mon message d'erreur:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
choix cannot be resolved
choix cannot be resolved
choix cannot be resolved
choix cannot be resolved
at sdz1.main(sdz1.java:55)
Mon code:
----------------------------------------------------------------------
import java.util.Scanner;
public class sdz1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner lire = new Scanner (System.in);
do{
double premier;
double second;
int choix;
double res;
System.out.println("Saisissez un premier nombre");
premier = lire.nextDouble();
System.out.println("Saisissez un deuxième nombre");
second = lire.nextDouble();
System.out.print("1 pour ajouter /n" +
"2 pour soustraire /n" +
"3 pour multiplier /n" +
"4 pour diviser /n" +
"5 pour quitter");
choix = lire.nextInt();
switch (choix){
case '1':
res = (premier+second);
System.out.println("Le résultat est " + res);
break;
case '2':
res = (premier-second);
System.out.println("Le résultat est " + res);
break;
case '3':
res = (premier*second);
System.out.println("Le résultat est " + res);
break;
case '4':
res = (premier/second);
System.out.println("Le résultat est " + res);
break;
Default:
System.out.println("Erreur de programmation");
}
}
while ( (choix ==1) || (choix ==2) || (choix ==3) || (choix ==4) );
}
}
-----------------------------------------------------------------------
Et mon message d'erreur:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
choix cannot be resolved
choix cannot be resolved
choix cannot be resolved
choix cannot be resolved
at sdz1.main(sdz1.java:55)