【发布时间】:2021-12-06 21:02:58
【问题描述】:
我已经正确设置了代码,没有错误,但似乎是因为即使我输入的整数高于程序的限制,它仍然会继续到下一行 | 这是更好理解的代码:
do {
System.out.print("Enter the grade of the student for the subject " + counter + ": ");
grade = Integer.parseInt(kbd.nextLine());
if (grade < 65) {
System.out.println("Grades Range only from 65-99!");
}
if (grade > 99) {
System.out.println("Grades Range only from 65-99!");
}
} while (grade > 65 && grade < 99);
do {
System.out.print("Enter the number of units for the subject " + counter + ": ");
units = Integer.parseInt(kbd.nextLine());
if (units < 1) {
System.out.println("Units Range only from 1-12!");
}
if (units > 12) {
System.out.println("Units Range only from 1-12!");
}
} while (units > 1 && units < 12);
【问题讨论】:
-
所以如果你输入
200那么(grade > 65 && grade < 99)是假的 -
是的,它将循环直到用户输入该范围内的整数
-
不,while 不正确,它不会循环
-
你想说loop while number小于65或大于99
-
我该如何改变它
标签: java loops validation do-while