Java如何使用while循环语句?
下面的代码演示了如何使用whileloop语句。该while语句将检查其表达式是否求值true并执行while语句块。
当countDown值大于或等于零时,将执行以下程序。
package org.nhooo.example.lang;
public class WhileDemo {
public static void main(String[] args) {
//从10开始倒数
int countDown = 10;
//做倒计时过程,而
//countDown大于或等于零。
while (countDown >= 0) {
System.out.println(countDown);
countDown--;
try {
//增加一秒钟的延迟。
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}