aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes can any one explain Two -Dimensional Arrays (code) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "can any one explain Two -Dimensional Arrays (code)" Watch "can any one explain Two -Dimensional Arrays (code)" New topic
Author

can any one explain Two -Dimensional Arrays (code)

Sekhar Velagala
Greenhorn

Joined: Apr 04, 2006
Posts: 6
Can anyone explain this code...what is the use of firset of for loops and second set of for loops:

Class array{
public static void main(String args[]){
int a[][] = new int [4][5];
int i,j, k=0;

for(i=0;i<4;i++)
for(j=0;j<n;j++){
a[i][j]=k;
k++;
}


for(i=0;i<4;i++){
for(j=0;j<n;j++)
System.out.print(a[i][j] + "");
System.out.println();
}
}
}


Thanks,
Sekhar
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

what exactly is the variable n doing here ? this code will not compile. variable n is not declared.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Sekhar Velagala
Greenhorn

Joined: Apr 04, 2006
Posts: 6
Hello John,

I am sorry...i mistyped the character...it is 5 instead of n in for loop...

Thanks,
Sekhar
Arno Reper
Ranch Hand

Joined: Mar 14, 2006
Posts: 286
hi,
an array of array is what we call in french "a matrice" , you have two for-loop because you have to move trough the rows and columns like :

its like chess or every GridGame
i hope this help,
arno


The man who makes no mistakes does not usually make anything<br /> <br />>>> SCJP 5.0 >> SCJD B&S <<< In progress
Naresh Gunda
Ranch Hand

Joined: Oct 15, 2005
Posts: 163
a[4][5] -> Array 'A' contains 4 rows , 5 columns. By default Array index starts with zero.

[ April 09, 2006: Message edited by: Naresh Kumar ]
Arno Reper
Ranch Hand

Joined: Mar 14, 2006
Posts: 286
ups it wasn't a[5][4],
my apologizes...
arno
Swosti Dipan Pal
Ranch Hand

Joined: Sep 23, 2005
Posts: 70
The main purpose of the first set of loop is to intialize the value of the array elements with the value of k.

The second set is used to display the values of the array element.

Cheers,
-Biswa


Thanks<br />-Swosti
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can any one explain Two -Dimensional Arrays (code)