Friday, November 12, 2010

Listing Array pada bahasa Java (LA AP1 minggu ke 6)

class contohArray2
{
public static void main(String [] args)
{
int matriks [][] = new int [6][5];
//isi matriksnya
matriks [0][0]=1;
matriks [0][1]=5;
matriks [0][2]=9;

matriks [1][0]=2;
matriks [1][1]=6;
matriks [1][2]=10;

matriks [2][0]=2;
matriks [2][1]=7;
matriks [2][2]=11;

matriks [3][0]=4;
matriks [3][1]=8;
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("   ");

matriks [0][0]=12;
matriks [0][1]=11;
matriks [0][2]=10;

matriks [1][0]=9;
matriks [1][1]=8;
matriks [1][2]=7;

matriks [2][0]=6;
matriks [2][1]=5;
matriks [2][2]=4;

matriks [3][0]=3;
matriks [3][1]=2;
matriks [3][2]=1;

for (int i=0; i<=3; i++){
for (int j=0; j<=2; j++){

System.out.print(matriks [i][j]+ "   ");
}
System.out.println("   ");
}
}
}

No comments:

Post a Comment