Question: Given the code fragment: int[][] array = {{0},{0,1},{0,2,4},{0,3,6,9},{0,4,8,12,16}}; System.out.println(array[4][1]); System.out.println(array[1][4]); What is the result? a. 4 null b. null 4 c. An illegalArgumentException is thrown

Given the code fragment:

int[][] array = {{0},{0,1},{0,2,4},{0,3,6,9},{0,4,8,12,16}};

System.out.println(array[4][1]);

System.out.println(array[1][4]);

What is the result?

a. 4 null

b. null 4

c. An illegalArgumentException is thrown

d. 4

An Array Index OutOfBoundException is thrown.

I know the answer is d; however, can you explain line 2 of the code fragment? I am not sure why 4 is being printed.

**I figured it out. I was counting 1,2,3,4,5 when I should of been counting 0,1,2,3,4 for the rows and columns.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!