【发布时间】:2021-01-01 08:45:04
【问题描述】:
如何使用扫描仪验证描述为 Y 和 N 的 2 个字符串之间的输入?
System.out.println("Are you sure?");
String StrInput = scan.nextLine();
if(strInput = Y && StrInput = N){
System.out.println("Nice choice");
}else{
System.out.println("Please Input only with Y or N");
}
【问题讨论】:
-
我知道它不起作用,但我想知道正确的逻辑,我不知道,请帮忙,谢谢!
-
使用String类的
equals()方法检查两个字符串的相等性,如strInput.equals("Y") -
谢谢!它有效
标签: java validation input