Given the code fragment:
int b = 3;
if (!(b > 3)) {
System.out.println("square ");
}{
System.out.println("circle ");
}
System.out.println("...");
What is the result?
A.
square
...
...
B.
circle
...
...
C.
square
circle
...
circle
...
D. Compilation fails.
题解
b 的变量数值为 3,程序第 4 行的 if 条件式「b 不大于 3」成立,先输出「square 」。接着注意第 6 行 if 区块中止的位置,他并没有使用 else 或是 else if 关键字,而直接使用了一个新的程序区块,这样的作法是可以被接受的,程序会继续运行到第 7 行,输出「circle 」。最后运行到第 9 行,输出「...」。
