我是Java编程的新手,所以我不确定这是否是最简单的方法,并且花了几个小时试图解决这个问题。
该程序的System.out.println(“响应(是)或(否)...”);
部分最初没有响应空的用户输入,而是两次显示上述文本。在第一个不正确的输入之后,它的行为应为??
`package qaCoursework;
import java.util.Scanner;
public class Test2 {
public static void main(String[] args) {
Scanner Input = new Scanner(System.in);
System.out.println("Enter Name...");
String name = Input.nextLine();
System.out.println("Enter age...");
int age = Input.nextInt();
System.out.println("Do you like programming ...?");
while (true) {
String Response = Input.nextLine();
if (Response.equalsIgnoreCase("yes")) {
System.out.println(name + " is " + age + " and loves programming");
break;
}
else if (Response.equalsIgnoreCase("no")) {
System.out.println(name + " is " + age + " and hates computers ...!");
break;
}
else {
System.out.println("Respond (Yes) or (No) ...");
}
}
}
}`