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 ();
程序必须使用char来查看用户是否想要重新启动程序,以便它只能抓取用户输入的第一个字符,并且不应区分大小写。它应该查找“y”或“n”,如果用户说“否”,则它结束程序。
答案 0 :(得分:0)
你需要一段时间的逻辑条件。也许
program.toUpperCase().equals("Y")
答案 1 :(得分:0)
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');
答案 2 :(得分:0)
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');