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 to Expert-Tailored 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

Recommended Textbook for

Database Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions

Question

Describe contextual influences on direct financial compensation.

Answered: 1 week ago

Question

Describe legally required benefits.

Answered: 1 week ago

Question

Discuss career development and career development methods.

Answered: 1 week ago