About Question enthuware.ocajp.i.v7.2.1381 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
kirankumar
Posts: 5
Joined: Tue Apr 05, 2016 10:25 am
Contact:

About Question enthuware.ocajp.i.v7.2.1381 :

Post by kirankumar »

int [] [] array = {{0}, {0, 1}, {0, 1, 2}, {0, 1, 2, 3}, {0, 1, 2, 3, 4}};

Is it two dimensional array? if yes, how?

kirankumar
Posts: 5
Joined: Tue Apr 05, 2016 10:25 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1381 :

Post by kirankumar »

The above statement is equivalent to below steps:

int [][] a = new int[5][5];
a[0] = new int[1];
a[1] = new int[2];
a[2] = new int[3];
a[3] = new int[4];
a[4] = new int[5];

a[0][0] = 0;

a[1][0] = 0;
a[1][1] = 1;

a[2][0] = 0;
a[2][1] = 1;
a[2][2] = 2;

a[3][0] = 0;
a[3][1] = 1;
a[3][2] = 2;
a[3][4] = 3;

a[4][0] = 0;
a[4][1] = 1;
a[4][2] = 2;
a[4][4] = 3;
a[4][5] = 4;

Can you please correct me If I am wrong?

Meghana
Posts: 29
Joined: Sun Feb 11, 2018 3:13 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1381 :

Post by Meghana »

Why does it not compile though?
(I had selected option 1: 1 1)

Online
admin
Site Admin
Posts: 10384
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1381 :

Post by admin »

This is a two dimensional array but the array pointed to by the variable arr1 is not. So arr1[4][1] cannot compile. This is explained in the explanation.

Meghana
Posts: 29
Joined: Sun Feb 11, 2018 3:13 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1381 :

Post by Meghana »

Oh.. Thank you! :)

flex567
Posts: 202
Joined: Mon Apr 02, 2018 8:40 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1381 :

Post by flex567 »

This would be the case in which ArrayIndexOutOfBoundsException would be thrown?

Code: Select all

System.out.println (array[4][10]);
In what case would the IllegalArgumentException be thrown?


IrinaFF
Posts: 1
Joined: Sun Oct 20, 2019 4:57 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1381 :

Post by IrinaFF »

I get a compilation error on line "System.out.println (arr1[4][1]);"
Array type expected; found: 'int'

Online
admin
Site Admin
Posts: 10384
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1381 :

Post by admin »

IrinaFF wrote:
Sun Oct 20, 2019 5:01 am
I get a compilation error on line "System.out.println (arr1[4][1]);"
Array type expected; found: 'int'
Please post complete and exact code that you are trying to compile.

Post Reply

Who is online

Users browsing this forum: admin and 9 guests