epi*_*icz 3 java boolean while-loop
我试图提示用户再次旋转,我的"while"表达总是回复为假...任何人都有任何想法?
reSpin = false;
if (reSpin == false){
System.out.println("Would you like to spin again? Y/N");
char ans = in.next().charAt(0);
if (ans == 'Y'){
reSpin =true;
}else if (ans == 'N'){
System.out.println("Thank you for playing!");
}else {
while ((ans != 'N') || (ans != 'Y')) {
System.out.println("Invalid answer, please only enter Y/N");
System.out.println("Would you like to spin again? Y/N");
ans = in.next().charAt(0);
}
}
}
Run Code Online (Sandbox Code Playgroud)
您可能想要使用:
while ((ans != 'N') && (ans != 'Y')) {
Run Code Online (Sandbox Code Playgroud)
检查ans是否不是N 而不是Y.如果你||在那里使用(或),那么它将检查ans是否不是N,或者不是Y(对于任何值都是如此ans).
| 归档时间: |
|
| 查看次数: |
375 次 |
| 最近记录: |