Given the code fragment:
if (aVar++ < 10) {
System.out.println(aVar + " Hello World!");
} else {
System.out.println(aVar + " Hello Universe!");
}
What is the result if the integer aVar is 9?
A.
10 Hello World!
B.
Hello Universe!
C.
Hello World!
D. Compilation fails.
题解
「++」操作符若放置于变量后面,会先取值才会进行变量值再加一的动作,因此这边的 if 条件式会成立,而输出「10 Hello World!」。
