public class Array2
{
public static void main(String[] args)
{
int matriks [][] = new int [4][5];
matriks [0][0]=1;
matriks [0][1]=2;
matriks [0][2]=3;
matriks [1][0]=4;
matriks [1][1]=5;
matriks [1][2]=6;
matriks [2][0]=7;
matriks [2][1]=8;
matriks [2][2]=9;
matriks [3][0]=10;
matriks [3][1]=11;
matriks [3][2]=12;
for (int i=0;i<=3;i++)
{
for (int j=0;j<=2;j++)
{
System.out.print(matriks [i][j]+" ");
}
System.out.println(" ");
}
System.out.println(" ");
int matriks2 [][] = new int [5][5];
matriks2 [0][0]=12;
matriks2 [0][1]=11;
matriks2 [0][2]=10;
matriks2 [1][0]=9;
matriks2 [1][1]=8;
matriks2 [1][2]=7;
matriks2 [2][0]=6;
matriks2 [2][1]=5;
matriks2 [2][2]=4;
matriks2 [3][0]=3;
matriks2 [3][1]=2;
matriks2 [3][2]=1;
for (int a=0;a<=3;a++)
{
for (int b=0;b<=2;b++)
{
System.out.print(matriks2 [a][b]+" ");
}
System.out.println(" ");
}
}
}
Contoh program array pada Java
Diposting oleh
Cherubim M. Janggi
Minggu, 28 November 2010
0 komentar:
Posting Komentar