contoh 1:
public static void main(String[] args){
int[][] arr = {{5,23,3},{6,72,9}};
System.out.println("arr[1][2] + arr[0][0] = "+(arr[1][2] + arr[0][0]));
System.out.println("arr[1][1] - arr[0][1] = "+(arr[1][1] - arr[0][1]));
System.out.println("arr[1][1] / arr[0][2] = "+(arr[1][1] / arr[0][2]));
System.out.println("arr[1][2] * arr[1][0] = "+(arr[1][2] * arr[1][0]));
}
contoh 2:
public static void main(String[]args){
// cara 1 ukuran 3 * 3 = 9
int[][] x;
x = new int[3][3];
x[0][0]=1;
x[0][1]=2;
x[0][2]=3;
x[1][0]=4;
x[1][1]=5;
x[1][2]=6;
x[2][0]=7;
x[2][1]=8;
x[2][2]=9;
System.out.println("Nilai x[0][0] : "+x[0][0]);
System.out.println("Nilai x[0][1] : "+x[0][1]);
System.out.println("Nilai x[0][2] : "+x[0][2]);
System.out.println("Nilai x[1][0] : "+x[1][0]);
System.out.println("Nilai x[1][1] : "+x[1][1]);
System.out.println("Nilai x[1][2] : "+x[1][2]);
System.out.println("Nilai x[2][0] : "+x[2][0]);
System.out.println("Nilai x[2][1] : "+x[2][1]);
System.out.println("Nilai x[2][2] : "+x[2][2]);
}
Tidak ada komentar:
Posting Komentar