Page 1 of 1

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

Posted: Fri Mar 08, 2013 4:06 pm
by muttley
I think that in this sentence:
daaa[0] should be a 2 dimensional array because daaa is a 3 dimensional array.
You meant:
d should be a 2 dimensional array because daaa is a 3 dimensional array.
Right?

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

Posted: Fri Mar 08, 2013 4:41 pm
by admin
Yes, you could say it that way. Assuming that you are talking about option 1, what ever you assign to daaa[0], should be a 2 D array. But d is not a 2 D array. So the assignment is invalid.

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

Posted: Mon Mar 11, 2013 1:40 pm
by lordnovas
Hey quick question:

What is the rule(s) concerning assigning values to 2D/3D array elements? What I currently see is that if you have a 3D array then you must use a 2D array to assign a value to an element within the 3D array, however I'm not sure why?

Is it because a 2D array can fit into a 3D array, or is it because of the array type, like a 2D array can fit into a 3D array?

Thanks in advance

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

Posted: Mon Mar 11, 2013 3:17 pm
by admin
Consider this. If you have a one dimensional array of ints (i.e. int[] ia), what would each element be? An int, right?

So if you have a two dimensional array of ints (i.e. int[][]) , which basically means an array or array of ints i.e. a 2D array, what would be the type of the first element of the top most array?

By the way, you should not talk of Java arrays in dimensions because arrays are not like matrix in java. In other words, Java arrays are not necessarily symetrical like a rectangular matrix. They are jagged. You should talk of them in terms of arrays of arrays of arrays...

You should read about it from a book because it is too much to explain in a forum.

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

Posted: Tue Mar 12, 2013 12:50 pm
by lordnovas
Ahhh, I get it. I think my approach/language was flawed. To insure I have it down below is my description for the arrays. Is that language better. I'm currently using the OCA Java7 study guide, and all of my Java training has been self taught, which is probably why I ask the dumbest questions - but please bare with me.

This is an integer Array, that stores integer values.

Code: Select all

int[] a;
This is a 2D Array, that stores an Array of integer Arrays

Code: Select all

int[][] b;
This is a 3D Array of type int, that stores an Array of 2D Arrays of type integer

Code: Select all

int[][][] c;

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

Posted: Tue Mar 12, 2013 12:52 pm
by admin
correct.

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

Posted: Tue Mar 12, 2013 9:32 pm
by lordnovas
Awesome thanks again.

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

Posted: Tue Mar 13, 2018 8:02 pm
by gwake1
int[] d1 = new int[]{};

int[][]d2 = new int[][]{};

int [][] d2Demo = new int[][]{new int[]{}};

int[][][] d3 = new int[][][]{};

int[][][]d3Demo = new int[][][]{new int[][]{new int[]{}}};

int [][][] d3MindBlown = new int[][][]{ d2 = new int[][]{ d1 = new int[]{} } };