• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multi Dim Array Question

 
Mike Cunningham
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's safe to say we will probably be tested on this concept during the SCJP exam.
I'm not sure of the answer though....
Array 1:
int[][] arrayA = new int[5][10];
- Per my reading material...the first index operator represents five rows...second index represents 10 columns.
Array 2:
int[][] arrayA = { {1,2,3} , {4,5,6} , {7,8,9} };
- I don't understand the nested curly braces method...please help.
- Mike
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right,
1. 5 rows 10 columns
2. 3 rows 3 columns as in
row 0: 1,2,3
row 1: 4,5,6
row 2: 7,8,9
This is a short way of declaring and initializing an array in one shot !
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
Mr Iftikhar
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can see this array in this direction for you convienient.
int[][] arrayA = { {1,2,3} ,
{4,5,6} ,
{7,8,9} };
Now it become 3x3( rows by column ) matrix and in java it contain 0,1,2 rows as well as 0,1,2 column.

----> Row0 Column0 Row0 Column1 Row0 Column2
----> Row1 Column0 Row1 Column1 Row1 Column2
----> Row2 Column0 Row2 Column1 Row2 Column2


 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic