【发布时间】:2015-07-02 12:04:59
【问题描述】:
我的这部分代码有问题。该程序要求输入几个输入(姓名、ID、等级等),然后将结果打印回来。
我决定脱离教程,现在一直在用众所周知的墙壁砸我的头 -
我想要的伪代码:
Ask user for grade between 9 and 12
If input is less than 9 or greater than 12, return failed message and -return to loop-
If input acceptable, continue to next question.
当前代码如下:
do {
System.out.print("Grade (9-12): ");
while (!keyboard.hasNextInt()) {
System.out.printf("message saying you're wrong");
keyboard.next();
}
userGrade = keyboard.nextInt();
} while (userGrade >= 9 || userGrade <= 12);
【问题讨论】:
-
你能具体说明你的代码有什么问题吗?什么没有按预期工作?
-
嗯,就目前而言,程序只是卡在一遍又一遍地询问成绩。我是否输入了无效(12)或有效(9-12)响应。
-
while (userGrade >= 9 || userGrade
标签: java validation input