Need help using specifically a do-while loop to run a program again

Tags: java do-while
Question!
do {
    System.out.println("Would you like to run this program again? Type Y for yes or N for no.");

    String program = keyboard.nextLine();
    char restart = program.charAt(0);
} while ();

The program has to use a char to see whether or not if the user wants to restart the program so it can grab just the first character the user inputs and it shouldn't be case sensitive. It should look for "y" or "n" and if the user says no then it ends the program.



Answers
char input = 'Y';
do {
    System.out.println("Would you like to run this program again? Type Y for yes or N for no.");

    String program = keyboard.nextLine();
    input = program.charAt(0);
} while(input == 'Y');


char restart = 'y';

do {
    System.out.println("Would you like to run this program again? Type Y for yes or N for no.");

    String program = keyboard.nextLine();
    restart = program.charAt(0);
} while (restart.toLower() == 'y');


You need a logical condition in the while. Perhaps

program.toUpperCase().equals("Y")
By : nicomp


This video can help you solving your question :)
By: admin