File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Multi Dim Array Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Multi Dim Array Question" Watch "Multi Dim Array Question" New topic

Multi Dim Array Question

Mike Cunningham
Ranch Hand

Joined: Nov 14, 2000
Posts: 130
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

Joined: Aug 26, 2001
Posts: 7610
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 !
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform

[Blog] [Blogroll] [My Reviews] My Linked In
Mr Iftikhar
Ranch Hand

Joined: Oct 12, 2001
Posts: 39
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

java language
I agree. Here's the link:
subject: Multi Dim Array Question
It's not a secret anymore!