Given the following code:

int[] intArr = {15, 30, 45, 60, 75};
intArr[2] = intArr[4];
intArr[4] = 90;

What are the values of each element in intArr after this code has executed?

A.

15, 60, 45, 90, 75

B.

15, 90, 45, 90, 75

C.

15, 30, 75, 60, 90

D.

15, 30, 90, 60, 90

E.

15, 4, 45, 60, 90

題解

這題要注意 Java 的陣列索引是從 0 開始的。

第 2 行程式執行後,陣列的內容為 {15, 30, 75, 60, 75}。

第 3 行程式執行後,陣列的內容為 {15, 30, 75, 60, 90}。