Closed. This question is off-topic。它当前不接受答案。
想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
4年前关闭。
我是Java新手,似乎找不到我的问题的答案。
我不确定嵌套循环是否正确。
仅当人员未对以下问题输入“是”或“否”时,才必须执行“ do while”内部的“ while循环”:
但是事实证明,如果我输入“是”或“否”,则循环仍在执行。
如果有人指出我在做什么错,我将不胜感激! ”
应该这样更改为
想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
4年前关闭。
我是Java新手,似乎找不到我的问题的答案。
我不确定嵌套循环是否正确。
仅当人员未对以下问题输入“是”或“否”时,才必须执行“ do while”内部的“ while循环”:
input = JOptionPane.showInputDialog("Do you have more grades to input? Please type 'Yes' or 'No'.");
但是事实证明,如果我输入“是”或“否”,则循环仍在执行。
如果有人指出我在做什么错,我将不胜感激! ”
String input;
int grade;
do {
input = JOptionPane.showInputDialog("Enter the midterm grades, please");
grade = Integer.parseInt(input);
if ( grade < 0 || grade > 100 ) {
input = JOptionPane.showInputDialog("You have entered an invalid grade. The grade should be a number between 0 and 100. Enter the midterm grades, please.");
grade = Integer.parseInt(input);
}
input = JOptionPane.showInputDialog("Do you have more grades to input? Please type 'Yes' or 'No'.");
while ( (!input.equals("Yes")) || (!input.equals("No")) ) {
input = JOptionPane.showInputDialog("You should type 'Yes' if you want to input more grades or 'No' if you are done with inputing grades. Do you have more grades to input? Please type 'Yes' or 'No'.");
if ( (input.equals("Yes")) || (input.equals("No")) ) {
break;
} else {
continue;
}
}
} while ( input.equals("Yes") );
最佳答案
看起来像这样:
while ( (!input.equals("Yes")) || (!input.equals("No")) ) {
应该这样更改为
&&
:while ( (!input.equals("Yes")) && (!input.equals("No")) ) {