simple 2d array of 4x6
public class arraytest
{
public static void main(String [] args)
{
int array[][]=new int [4][6];
int row=array.length;
int col=array[0].length;
System.out.println("Row length " +row);
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
{
array[1][1]=5;
System.out.println("Array elements " +array[i][j]);
}
}
}
how does array[1][1]=5 functions: The output is as follows:
Row length 4
Array elements 0
Array elements 0
Array elements 0
Array elements 0
Array elements 0
Array elements 0
Array elements 0
Array elements 5
Array elements 0
Array elements 0
Array elements 0
Array elements 0
Array elements 0
Array elements 0
Array elements 0
Array elements 0
Array elements 0
Array elements 0
Array elements 0
Array elements 0
Array elements 0
Array elements 0
Array elements 0
Array elements 0
how come "Array elements 5" is in 8th position, i couldnt understand the logic. >can anyone explain the logic.
Aucun commentaire:
Enregistrer un commentaire