• Post Reply Bookmark Topic Watch Topic
  • New Topic
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ups it wasn't a[5][4],
my apologizes...
arno
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic