programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# can any one explain Two -Dimensional Arrays (code)

Greenhorn
Posts: 6
• Number of slices to send:
Optional 'thank-you' note:
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

Bartender
Posts: 6663
5
• Number of slices to send:
Optional 'thank-you' note:
what exactly is the variable n doing here ? this code will not compile. variable n is not declared.

Sekhar Velagala
Greenhorn
Posts: 6
• Number of slices to send:
Optional 'thank-you' note:
Hello John,

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

Thanks,
Sekhar

Ranch Hand
Posts: 286
• Number of slices to send:
Optional 'thank-you' note:
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

Ranch Hand
Posts: 163
• Number of slices to send:
Optional 'thank-you' note:
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
• Number of slices to send:
Optional 'thank-you' note:
ups it wasn't a[5][4],
my apologizes...
arno

Ranch Hand
Posts: 70
• Number of slices to send:
Optional 'thank-you' note:
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

 Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters?