✏️ Explanatory Question

(ix)
(a) Write the Java statement to initialize the first 6 odd numbers in a 3 × 2 array.

(b) What is the result of x[0][1] + x[2][1] of the above array?

👁 74 Views
📘 Detailed Answer
🟢 Easy
💡

Answer with Explanation

(a) Java statement to initialize the first 6 odd numbers in a 3 × 2 array:


int[][] x = {
    {1, 3},
    {5, 7},
    {9, 11}
};

(b) Calculation of x[0][1] + x[2][1]:

  • x[0][1] refers to the element at row 0, column 1, which is 3.

  • x[2][1] refers to the element at row 2, column 1, which is 11.

Result:
x[0][1] + x[2][1] = 3 + 11 = 14