Answer the question
In order to leave comments, you need to log in
How to finish the code so that everything works and when you enter "n" the program ends?
Does not work, when you enter "n" nothing happens.
It should end the program when you enter "n" (there is no code after the cycle), and when you press "y" return to the beginning of the cycle.
Please help
while(true){
//HERE
//CODE
String input = scanner.next();
if (input == "n") {break;}
}
Answer the question
In order to leave comments, you need to log in
I haven't written in java for a long time. I think something like this:
String str=""
while(!str.equals("n")){
//КОД
str = scanner.next();
}
while(!scanner.next().equals("n")){
//код
}
Strings are objects, which means you can only compare using equal()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question