Je suis tout à fait nouveau à java et très nouveau à faire en boucle. J'ai un problème avec la boucle, j'ai fait une calculatrice de base et lui ai donné une option pour calculer autre chose après avoir calculé quelque chose. Lorsque cette option vient et que j'entre "Y" (majuscule), elle "redémarre" mais si je réponds "y" (minuscule) cela revient à ce que vous avez choisi. Donc par exemple: Si je démarre la calculatrice, j'obtiens 5 options, si je choisis l'option numéro 1 et j'arrive à la fin, j'ai le choix: Si je veux "essayer à nouveau", donc si je choisis de répondre "Y" le tout retourne à l '"écran" où je dois faire mon choix sur ce qu'il faut faire. Mais quand je choisis de répondre "y", cela revient au point de mon choix précédent. Comme si je choisis l'option 1 et que je réponds «y», cela revient à l'option 1.Faire tandis que la boucle commence au mauvais point [Java]
J'ai essayé de chercher en ligne mais je n'ai rien trouvé, donc je ne sais pas utiliser les bons mots-clés ou faire d'autres personnes pas rencontré mon problème très souvent.
Voici la calculatrice, il y a quelques mots hollandais en elle comme calculatrice ou très mauvais anglais, mais aucun d'entre eux comptent en aucune façon:
import java.util.*;
public class GEKENMCHINENENE {
public static void main(String[] args){
char aga = 'y';
while(aga == 'y' || aga == 'Y'){
Scanner antwoord = new Scanner(System.in);
int aw;
do{
System.out.println("enter 1 for addition. enter 2 for subtraction. enter 3 for division. enter 4 for multiplication.");
System.out.println("+------------------------------+");
System.out.println("| Calculator |");
System.out.println("|------------------------------|");
System.out.println("| Press 1 for addition |");
System.out.println("| Press 2 for subtraction |");
System.out.println("| Press 3 for division |");
System.out.println("| Press 4 for multiplication |");
System.out.println("| Press 5 for my social media |");
System.out.println("| *credit to creepershelp* |");
System.out.println("| *on pastebin* |");
System.out.println("+------------------------------+");
aw = antwoord.nextInt();
do{
if (aw > 5){
System.out.println("That number is out of range, try aga within the range of 1 - 4");
aw = antwoord.nextInt();
}else if(aw < 1){
System.out.println("That number is out of range, try aga within the range of 1 - 4");
aw = antwoord.nextInt();
}else if(aw < -1){
System.out.println("That number is out of range, try aga within the range of 1 - 4");
aw = antwoord.nextInt();
}
if(aw == 1){
System.out.println("You choose for 1, addition. Enter your first number.");
double fnum = antwoord.nextDouble();
System.out.println("Enter your second number");
double snum = antwoord.nextDouble();
double awp = fnum + snum;
System.out.println("The answer is " + awp);
System.out.println("Wood you like to reken uit something else? [Y/N]");
aga = antwoord.next().charAt(0);
if(aga == 'n'){
System.out.println("Shutting down...");
}if(aga == 'n'){
aga = 'n';
antwoord.close();
break;
}else if(aga == 'N'){
System.out.println("Shutting down...");
}if(aga == 'N'){
aga = 'N';
antwoord.close();
break;
}else if(aga == 'y'){
System.out.println("Please wait!");
}else if(aga == 'Y'){
System.out.println("Please wait!");
aw = 0;
}
}
if(aw == 2){
System.out.println("You choose for 2, subtraction. Enter your first number.");
double fnum = antwoord.nextDouble();
System.out.println("Enter your second number");
double snum = antwoord.nextDouble();
double awp = fnum - snum;
System.out.println("The answer is " + awp);
System.out.println("Wood you like to reken uit something else? [Y/N]");
aga = antwoord.next().charAt(0);
if(aga == 'n'){
System.out.println("Shutting down...");
}if(aga == 'n'){
aga = 'n';
antwoord.close();
break;
}else if(aga == 'N'){
System.out.println("Shutting down...");
}if(aga == 'N'){
aga = 'N';
antwoord.close();
break;
}else if(aga == 'y'){
System.out.println("Please wait!");
}else if(aga == 'Y'){
System.out.println("Please wait!");
aw = 0;
}
}
if(aw == 3){
System.out.println("You choose for 3, division. Enter your first number.");
double fnum = antwoord.nextDouble();
System.out.println("Enter your second number");
double snum = antwoord.nextDouble();
double awp = fnum/snum;
System.out.println("The answer is " + awp);
System.out.println("Wood you like to reken uit something else? [Y/N]");
aga = antwoord.next().charAt(0);
if(aga == 'n'){
System.out.println("Shutting down...");
}if(aga == 'n'){
aga = 'n';
antwoord.close();
break;
}else if(aga == 'N'){
System.out.println("Shutting down...");
}if(aga == 'N'){
aga = 'N';
antwoord.close();
break;
}else if(aga == 'y'){
System.out.println("Please wait!");
}else if(aga == 'Y'){
System.out.println("Please wait!");
aw = 0;
}
}
if(aw == 4){
System.out.println("You choose for 4, multiplication. Enter your first number.");
double fnum = antwoord.nextDouble();
System.out.println("Enter your second number");
double snum = antwoord.nextDouble();
double awp = fnum * snum;
System.out.println("The answer is " + awp);
System.out.println("Wood you like to reken uit something else? [Y/N]");
aga = antwoord.next().charAt(0);
if(aga == 'n'){
System.out.println("Shutting down...");
}if(aga == 'n'){
aga = 'n';
antwoord.close();
break;
}else if(aga == 'N'){
System.out.println("Shutting down...");
}if(aga == 'N'){
aga = 'N';
antwoord.close();
break;
}else if(aga == 'y'){
System.out.println("Please wait!");
}else if(aga == 'Y'){
System.out.println("Please wait!");
aw = 0;
}
}if(aw == 5){
System.out.println("Instagram: rubettt, https://www.instagram.com/rubettt/?hl=en");
System.out.println("Snapchat: rubet23-1212121");
System.out.println("Wood you like to reken uit something else? [Y/N]");
aga = antwoord.next().charAt(0);
if(aga == 'n'){
System.out.println("Shutting down...");
}if(aga == 'n'){
aga = 'n';
antwoord.close();
break;
}else if(aga == 'N'){
System.out.println("Shutting down...");
}if(aga == 'N'){
aga = 'N';
antwoord.close();
break;
}else if(aga == 'y'){
System.out.println("Please wait!");
}else if(aga == 'Y'){
System.out.println("Please wait!");
aw = 0;
}
}if(aw == 0){
System.out.println("Succesfully shut down!");
}else if(aga == 'n' || aga == 'N'){
System.out.println("Succesfully shut down!");
}
}while(aw > 1 && aw <329108321);
}while(aga == 'y' || aga == 'Y');
}
}
}
J'ai essayé de le faire changer « y » dans " Y "mais cela n'a pas fonctionné non plus. Si quelqu'un a des idées, aidez s'il vous plaît. J'aimerais savoir pourquoi c'est et comment je peux le réparer. Merci à l'avance,
-Rubet23
Que voulez-vous dire "Ne fonctionne pas"? StackOverflow n'est pas un remplacement de debugger –
Il est difficile de trouver des erreurs dans votre code, car il est vraiment déroutant de répéter des cas et est difficile à lire. Au lieu d'essayer de trouver l'erreur, vous devriez probablement réécrire le code et avant de le faire, vous devriez le planifier. Si tu veux, je peux t'aider mais à part ça, je ne peux pas faire grand-chose. – tomtzook
Créez un nouveau projet et supprimez tout votre code sauf la boucle do while. À la fin de votre boucle while do pose la question et sélectionnez une option. Si cela fonctionne correctement, commencez à ajouter votre autre code. – Sedrick