Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions