how to end a while loop with a certain variable

后端 未结 4 614
谎友^
谎友^ 2021-01-17 02:28

I am making an odd or even program with a while loop. I am trying to figure out how to end the while loop with a certain number. Right now I have 1 to continue the loop, and

4条回答
  •  半阙折子戏
    2021-01-17 03:09

    To exit the program when the user enters anything other than a Number, change the variable x type to a String

    if (!StringUtils.isNumeric(x)) {
        System.exit(0);
    }
    

    To exit the program when user enters 2

    if (x == 2) {
        System.exit(0);
    }
    

提交回复
热议问题