Sie sind auf Seite 1von 6

ARRAY 2D

Contoh Codingnya :
import java.util.Scanner;

public class Aray2dAritmatika {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

int i;

int j;

int[][]matrixA = new int[2][2];

int[][]matrixB = new int[2][2];

int[][]jumlah = new int[2][2];

int[][]kurang = new int[2][2];

int[][]kali = new int [2][2];

int[][]bagi = new int [2][2];

//input matrix A

for(i=1;i<2;i++)

for(j=1;j<2;j++)

System.out.print("Matrix A " + i + "." + j + "= ");

matrixA[i][j] =input.nextInt();

}
}

System.out.println();

// input matrix B

for(i=1;i<2;i++)

for(j=1;j<2;j++)

System.out.print("Matrix B " + i + "." + j + "= ");

matrixB[i][j] =input.nextInt();

//penjumlahan Matrix

for(i=1;i<2;i++)

for(j=1;j<2;j++)

jumlah[i][j] = matrixA[i][j] + matrixB[i][j];

kurang[i][j] = matrixA[i][j] - matrixB[i][j];

kali[i][j] = matrixA[i][j] * matrixB[i][j];

bagi[i][j] = matrixA[i][j] / matrixB[i][j];

}
//tampil matrix A

System.out.println("Tampil Matriks A");

for(i=1;i<2;i++)

for(j=1;j<2;j++)

System.out.print("" + matrixA[i][j]);

System.out.println();

//tampil matrix B

System.out.println("Tampil Matriks B");

for(i=1;i<2;i++)

for(j=1;j<2;j++)

System.out.print("" + matrixB[i][j]);

System.out.println();

//tampil jumlahMatrix B

System.out.println("Penjumlahan");

for(i=1;i<2;i++)

for(j=1;j<2;j++)
{

System.out.print("" + jumlah[i][j]);

System.out.println();

//tampil kurangmatrix

System.out.println("Pengurangan");

for(i=1;i<2;i++)

for(j=1;j<2;j++)

System.out.print("" + kurang[i][j]);

System.out.println();

//tampil kalimatrix

System.out.println("Perkalian");

for(i=1;i<2;i++)

for(j=1;j<2;j++)

System.out.print("" + kali[i][j]);

System.out.println();

}
//tampil bagimatrix

System.out.println("Pembagian");

for(i=1;i<2;i++)

for(j=1;j<2;j++)

System.out.print("" + bagi[i][j]);

System.out.println();

Hasil Output :

Matrix A 1.1= 10

Matrix B 1.1= 2

Tampil Matriks A

10

Tampil Matriks B

Penjumlahan

12

Pengurangan

Perkalian

20
Pembagian