+ 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

2nd Apr 2018, 3:16 PM
William Changco
William Changco - avatar
9 odpowiedzi
2nd Apr 2018, 3:35 PM
William Changco
William Changco - avatar
+ 3
hahahaha thank you so much😊😊
2nd Apr 2018, 3:42 PM
William Changco
William Changco - avatar
+ 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!
2nd Apr 2018, 3:22 PM
777
777 - avatar
+ 1
yes I'm trying on NetBeans right now but how about n?
2nd Apr 2018, 3:24 PM
William Changco
William Changco - avatar
+ 1
William Changco, can you please explain what you're asking?
2nd Apr 2018, 3:33 PM
777
777 - avatar
+ 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
2nd Apr 2018, 3:37 PM
William Changco
William Changco - avatar
+ 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 }
2nd Apr 2018, 3:42 PM
TurtleShell
TurtleShell - avatar
+ 1
@William Changco, I understood the program, and I'm working on your code. Stay tuned ;)
2nd Apr 2018, 3:42 PM
777
777 - avatar
+ 1
@777 Thanks, it helped me a lot
27th Oct 2023, 1:06 PM
CIS GRADE 5 A HAMZA SHEIKH
CIS GRADE 5 A HAMZA SHEIKH - avatar