需要帮助,特别是使用do-while循环来再次运行程序


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 ();

程序必须使用一个字符来查看用户是否想要重新启动程序,以便它可以抓取用户输入的第一个字符,并且它不应该区分大小写。它应该查找"y"或"n",如果用户说没有,它就结束程序。

while语句中需要一个逻辑条件。也许

program.toUpperCase().equals("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');
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');

最新更新