问题:
int x = 1, y =6;
while (y--) {
x++;
}
System.out.println(“x =” + x + “y =” +y);
What is the result?()
A . x = 6 y = 0
B . x = 7 y = 0
C . x = 6 y = -1
D . x = 7 y = -1
E . Compilation fails.
int x = 1, y =6;
while (y--) {
x++;
}
System.out.println(“x =” + x + “y =” +y);
What is the result?()
● 参考解析
A ‘while’ statement can only evaluate a Boolean expression. The expression while(y--) returns an int rather than a Boolean. Therefore, the correct answer is E.
相关内容
相关标签