在三次无效输入后,我需要第三次显示不同的内容并恢复到第一个循环。也不确定如何连续
do{
System.out.print("Enter Rating(-1 to quit): ");
rating = input.nextInt();
}
while (rating == 0 || rating == 1 || rating == 2 || rating == 3 || rating == 4);
System.out.print("Invalid entry. Please enter a whole number "
+ "or enter -1 to quit: ");
rating = input.nextInt();
答案 0 :(得分:0)
您可以使用while (rating < 0 || rating > 4)
答案 1 :(得分:0)
你是说这个吗?
/**
<P>{@code java Test}</P>
**/
public class Test {
public static final void main(String[] ignored) {
int iterationCount = 5;
for(int i = 0; i < iterationCount; i++) {
if(i == 2) { //Index of 3 is 2
System.out.println("Printing something special on the third iteration!");
//You could set i back to 0 here, if that's what you want...
} else {
System.out.println("Index " + i);
}
}
}
}
输出:
[C:\java_code\]java Test
Index 0
Index 1
Printing something special on the third iteration!
Index 3
Index 4