62,628
社区成员
发帖
与我相关
我的任务
分享System.out.println("请输入运算符:");
operator = input.nextLine();
//对运算符进行判断是否有该运算符
String[] scores = {"+","-","*","/","%"};
List lists = Arrays.asList(scores);
if (lists.contains(operator)) {
} else {
System.out.println("运算符输入错误,请重新输入");
operator = input.nextLine();
}
System.out.println("请输入运算符:");
operator = input.nextLine();
String[] scores = { "+", "-", "*", "/", "%" };
List lists = Arrays.asList(scores);
while(true){
if (lists.contains(operator)) {
// xxxxxxxxxxx
break;
} else {
System.out.println("运算符输入错误,请重新输入");
operator = input.nextLine();
}
}
用while(true),如果存在就break