Given the following main method:
public static void main(String[] args) {
int num = 5;
do {
System.out.print(num-- + " ");
} while (num == 0);
}
What is the result?
A.
5 4 3 2 1 0
B.
5 4 3 2 1
C.
4 2 1
D.
5
E. Nothing is printed
题解
do-while 循环第一次运行,输出「5 」并将 num 变量所保存的数值再减一,num=5-1=4。4 不等于 0,因此 while 条件式不成立,循环不再运行。所以只有输出「5 」。
