+ 1
What code is y/n in java if i want them to pick a choice?
What code should i use in java if i want to give them a choice like "Do you want to continue y/n?" If y continue to the next program and if n exit to the program
9 Antworten
+ 3
hahahaha thank you so much😊😊
+ 2
You can try something like...
char choice = 'y';
while(choice == 'y') {
... some code
}
// will terminate when choice would be No!
Although the above code wouldn't show desired results on SoloLearn!
+ 1
yes I'm trying on NetBeans right now but how about n?
+ 1
William Changco, can you please explain what you're asking?
+ 1
example code i want it to show in the end of the output to the user if they want to still continue or no if no then the program is no exit
+ 1
Scanner usrInput = new Scanner(System.in);
String input;
// Asks for input constantly until it gets y or n
do {
System.out.println("Question?y/n");
input = usrInput.nextLine();
} while (input.toLowerCase() != "y" || input.toLowerCase() != "n");
if (input.toLowerCase() == "y") {
//code
} else {
//code
}
+ 1
@William Changco, I understood the program, and I'm working on your code. Stay tuned ;)
+ 1
@777 Thanks, it helped me a lot