这个while循环有什么问题? [英] Whats wrong with this while loop?
本文介绍了这个while循环有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
boolean r = false ; int s = 0 ;
while (r == false) ;
{
s = getInt() ;
if (!(s>=0 && s<=2)) System.out.println ("try again not a valid response") ;
else r = true ;
}
即使输入3或123,文本也不会显示循环永远不会终止。这里有什么不对?
The text never displays itself even when a 3 or a 123 is entered and the loop never terminates. Whats wrong here?
推荐答案
条件后你有一个分号。当您使用大括号为指定块时,
则不使用分号。
You have a semicolon after the condition. When you use braces to specify a block for your while
you don't use a semicolon.
这篇关于这个while循环有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文