Home / Questions / (viii) Consider the following array and answer the questions given below: int a[ ] = {12,10,8,4,6,2,3,5,7}; (a) What is the output of System.out.print(a[0] + a[5]);? (b) What is the index (subscript) of the largest element of the array a[ ]?
Explanatory Question

(viii) Consider the following array and answer the questions given below:

int a[ ] = {12,10,8,4,6,2,3,5,7};

(a) What is the output of System.out.print(a[0] + a[5]);?

(b) What is the index (subscript) of the largest element of the array a[ ]?

👁 74 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

Given the array:


int a[] = {12,10,8,4,6,2,3,5,7};

(a) Finding the output of System.out.print(a[0] + a[5]);

  • a[0] = 12

  • a[5] = 2

  • a[0] + a[5] = 12 + 2 = 14

Output:


14

(b) Finding the index (subscript) of the largest element in the array

The given array is:
{12, 10, 8, 4, 6, 2, 3, 5, 7}

  • The largest element in the array is 12.

  • The index of 12 in the array is 0.

Answer:


Index = 0