Scanner in = new Scanner (System.in);
System.out.print("Masukan Baris = ");
int baris = in.nextInt();
System.out.print("Masukkan Kolom = ");
int kolom = in.nextInt();
int matrikA[][]=new int [baris][kolom];
int matrikB[][]= new int [baris][kolom];
int hasil[][]= new int [baris][kolom];
System.out.println("Inputan Matrik A = ");
for (int i = 0; i < matrikA.length; i++) {
for (int j = 0; j < matrikA[i].length; j++) {
System.out.print("Masukkan Baris "+i+" kolom "+j+" = ");
matrikA[i][j]=in.nextInt();
}
}
System.out.println("Inputan Matrik B = ");
for (int i = 0; i < matrikB.length; i++) {
for (int j = 0; j < matrikB[i].length; j++) {
System.out.print("Masukkan Baris "+i+" kolom "+j+" = ");
matrikB[i][j]=in.nextInt();
}
}
System.out.println("Keluaran Matrik A = ");
for (int i = 0; i < matrikA.length; i++) {
System.out.print(" ");
for (int j = 0; j < matrikA[i].length; j++) {
System.out.print(" "+matrikA[i][j]);
} System.out.print("\n");
}
System.out.println("Keluaran Matrik B = ");
for (int i = 0; i < matrikB.length; i++) {
System.out.print(" ");
for (int j = 0; j < matrikB[i].length; j++) {
System.out.print(" "+matrikB[i][j]);
} System.out.print("\n");
}
System.out.println("Hasil perkalian ");
for (int j = 0; j < matrikA.length ; j++) {
System.out.println("");
for (int k = 0; k < matrikA.length ; k++) {
hasil [j][k]=0;
for (int l = 0; l < matrikB.length; l++) {
hasil[j][k]+=matrikA[j][l]*matrikB[l][k];
}System.out.print(" "+hasil[j][k]);
}
}
System.out.println("\n");
System.out.println("===============================");
Tidak ada komentar:
Posting Komentar