#################一个小问题。初学者请教一下######################

ss19497 2017-02-24 04:25:40
System.out.println("请输入运算符:");
operator = input.nextLine();
//对运算符进行判断是否有该运算符
String[] scores = {"+","-","*","/","%"};
List lists = Arrays.asList(scores);
if (lists.contains(operator)) {

} else {
System.out.println("运算符输入错误,请重新输入");
operator = input.nextLine();
}


我通过验证运算符 等于数组的通过放行,输错的提示继续重新输入
要求!!!!再次输错在重新输入直到正确为止。这个怎么实现呀
...全文
159 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
忆寒哥哥耶 2017-02-24
  • 打赏
  • 举报
回复
引用 3 楼 zw0283 的回复:


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();
    }
}

恩。我在后面加了continue实现了
忆寒哥哥耶 2017-02-24
  • 打赏
  • 举报
回复
引用 5 楼 jiajing1990_ 的回复:
可以写个方法,然后用回调啊
谢谢 已解决
jiajing1990_ 2017-02-24
  • 打赏
  • 举报
回复
可以写个方法,然后用回调啊
李德胜1995 2017-02-24
  • 打赏
  • 举报
回复
引用 2 楼 ss19497 的回复:
引用 1 楼 pany1209 的回复:
用while(true),如果存在就break
while里面还有用if判断吗
zw0283 2017-02-24
  • 打赏
  • 举报
回复


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();
    }
}

忆寒哥哥耶 2017-02-24
  • 打赏
  • 举报
回复
引用 1 楼 pany1209 的回复:
用while(true),如果存在就break
while里面还有用if判断吗
李德胜1995 2017-02-24
  • 打赏
  • 举报
回复
用while(true),如果存在就break

62,628

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧