Fri Oct 10, 2008 12:07 am
int[] array1D; // Declares 1D array.
array1D = new int[5]; // memory allocation
int array1D = new int[5];
array1D[0]=54;
array1D[1]=11;
array1D[2]=43;
array1D[3]=74;
array1D[4]=84;
for(int i=0;i<array1D.length;i++)
{
System.out.println("Element#"+(i+1)+" - "+array1D[i]);
}
Element#1 - 54
Element#2 - 11
Element#3 - 43
Element#4 - 74
Element#5 - 84
int[][] array2D = new int[3][6];
int[][] array2D= new int[3][6];
array2D[0][4]=54;
array2D[1][5]=11;
array2D[2][2]=43;
System.out.println("array2D.length: "+array2D.length);
System.out.println("array2D[0].length: "+array2D[0].length);
for(int i=0;i<array2D.length;i++)
for(int j=0;j<array2D[0].length;j++)
{
System.out.println("Element#"+(i+1)+","+(j+1)+" - "+array2D[i][j]);
}
array2D.length: 3
array2D[0].length: 6
Element#1,1 - 0
Element#1,2 - 0
Element#1,3 - 0
Element#1,4 - 0
Element#1,5 - 54
Element#1,6 - 0
Element#2,1 - 0
Element#2,2 - 0
Element#2,3 - 0
Element#2,4 - 0
Element#2,5 - 0
Element#2,6 - 11
Element#3,1 - 0
Element#3,2 - 0
Element#3,3 - 43
Element#3,4 - 0
Element#3,5 - 0
Element#3,6 - 0
int[][][] array3D= new int[3][6][7];
Tue Jul 24, 2012 2:50 pm
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.