This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Arrays of Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Arrays of Arrays" Watch "Arrays of Arrays" New topic
Author

Arrays of Arrays

Armstrong D
Greenhorn

Joined: Apr 16, 2002
Posts: 7
can anybody explain this arrrays of arrays, i am getting confused with the nested for loops,
and what should i know in arrays of arrays as am preparing for the SCJP
class arr {
public static void main (String args[]) {
int twoD[][] = new int[2][3];
int i, j, k = 0;
for(i=0; i<2; i++)
for(j=0; j<3; j++) {
twoD[i][j] = k;
k++;
System.out.println(twoD[i][j]);
}
}
}
Thank you very much
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
In this case we have a bi-dimensional array. It is kind of like a matrix 2x3 (2 rows - 3 columns).
int twoD[][] = new int[2][3];
The nested for loops are needed in order to access each cell of the matrix.
for(int i=0;i<2;i++) will traverse the first and second row.
for(int j=0;j<3;j++) will traverse the first, the second and the third column.
Each cell is assigned k (incremented at each iteration). The content of the bi-dimensional array after its initialization is:


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Arrays of Arrays