如何使用扫描仪验证描述为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");
}
正如Rono所说,在输入检查之间使用Equals和||条件,它可以是Y或N。下面的代码片段将有助于
System.out.println("Are you sure?");
String strInput = scan.nextLine();
if(strInput.equals("Y") || strInput.equals("N")){
System.out.println("Nice choice");
}else{
System.out.println("Please Input only with Y or N");
}