Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can any one explain Two -Dimensional Arrays (code)

 
Sekhar Velagala
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what exactly is the variable n doing here ? this code will not compile. variable n is not declared.
 
Sekhar Velagala
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello John,

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

Thanks,
Sekhar
 
Arno Reper
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Naresh Gunda
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ups it wasn't a[5][4],
my apologizes...
arno
 
Swosti Dipan Pal
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic