【发布时间】:2015-06-29 12:15:58
【问题描述】:
//当用户键入 y OR n.. 时,我需要中断 while 循环。但到目前为止,我只能得到一个字母/字符串。
Scanner user_input = new Scanner(System.in);
String name = user_input.next();
System.out.print("Would you like to order some coffee, "+name+"? (y/n)");
String coffeeYorN = user_input.next();
while (!coffeeYorN.equals("y")||!coffeeYorN.equals"n") //HERE IS MY ISSUE
{
System.out.println("Invalid response, try again.");
System.out.print("Would you like to order some coffee, "+name+"? (y/n)");
coffeeYorN = user_input.next();
}
【问题讨论】:
标签: java string while-loop operators