About Question enthuware.ocajp.i.v7.2.1381 :
Moderator: admin
-
- Posts: 5
- Joined: Tue Apr 05, 2016 10:25 am
- Contact:
About Question enthuware.ocajp.i.v7.2.1381 :
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?
Is it two dimensional array? if yes, how?
-
- Posts: 5
- Joined: Tue Apr 05, 2016 10:25 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1381 :
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?
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?
-
- Posts: 29
- Joined: Sun Feb 11, 2018 3:13 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1381 :
Why does it not compile though?
(I had selected option 1: 1 1)
(I had selected option 1: 1 1)
Online
-
- Site Admin
- Posts: 10384
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1381 :
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.
-
- Posts: 29
- Joined: Sun Feb 11, 2018 3:13 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1381 :
Oh.. Thank you! 

-
- Posts: 202
- Joined: Mon Apr 02, 2018 8:40 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1381 :
This would be the case in which ArrayIndexOutOfBoundsException would be thrown?
In what case would the IllegalArgumentException be thrown?
Code: Select all
System.out.println (array[4][10]);
-
- Posts: 1
- Joined: Sun Oct 20, 2019 4:57 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1381 :
I get a compilation error on line "System.out.println (arr1[4][1]);"
Array type expected; found: 'int'
Array type expected; found: 'int'
Online
-
- Site Admin
- Posts: 10384
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Who is online
Users browsing this forum: admin and 9 guests