System.out.println(a [ (a = b)[3] ]);
首先,a
值進行評估({1, 2, 3, 4}
)。接下來,執行a = b
;這將b
的值分配給a
,並且返回的值b
。 b[3] = { 2, 3, 1, 0 }
是0
,所以最終是{1,2,3,4}[b[3]] = {1,2,3,4}[0] = 1
。
看到這一點,考慮以下因素:
public static void main(String[] args) throws FileNotFoundException {
int[] a = { 1, 2, 3, 4 };
System.out.println(a() [ (a = b())[c()] ]);
}
public static int[] a() {
System.out.println('a');
return new int[]{ 1, 2, 3, 4 };
}
public static int[] b() {
System.out.println('b');
return new int[]{ 2, 3, 1, 0 };
}
public static int c() {
System.out.println('c');
return 3;
}
輸出:
a
b
c
1
作業?你試過什麼了? –
你剛剛回答你的第一個問題嗎? –
我只是運行代碼並找出答案。 (或者如果你想仔細看一下調試器就行了。) – millimoose