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

Moderator: admin

Post Reply
muttley
Posts: 19
Joined: Thu Feb 28, 2013 9:47 am
Contact:

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

Post by muttley » Fri Mar 08, 2013 4:06 pm

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?

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

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

Post by admin » Fri Mar 08, 2013 4:41 pm

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.
If you like our products and services, please help us by posting your review here.

lordnovas
Posts: 12
Joined: Tue Jan 15, 2013 3:31 pm
Contact:

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

Post by lordnovas » Mon Mar 11, 2013 1:40 pm

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

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

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

Post by admin » Mon Mar 11, 2013 3:17 pm

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.
If you like our products and services, please help us by posting your review here.

lordnovas
Posts: 12
Joined: Tue Jan 15, 2013 3:31 pm
Contact:

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

Post by lordnovas » Tue Mar 12, 2013 12:50 pm

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;

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

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

Post by admin » Tue Mar 12, 2013 12:52 pm

correct.
If you like our products and services, please help us by posting your review here.

lordnovas
Posts: 12
Joined: Tue Jan 15, 2013 3:31 pm
Contact:

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

Post by lordnovas » Tue Mar 12, 2013 9:32 pm

Awesome thanks again.

gwake1
Posts: 1
Joined: Tue Mar 13, 2018 7:51 pm
Contact:

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

Post by gwake1 » Tue Mar 13, 2018 8:02 pm

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[]{} } };

Post Reply

Who is online

Users browsing this forum: bortnikov_sa@mail.ru and 17 guests