package matriks;
//import java.io.*;
import javax.swing.JOptionPane;
/**
* @author Muhammad Fairuz
*/
public class PERKALIAN_MATRIKS {
public static void main(String[] args) {
String Baris_A = JOptionPane.showInputDialog("Masukkan Jumlah Baris A:");
System.out.println("Jumlah Baris A = " + Baris_A);
String Kolom_A = JOptionPane.showInputDialog("Masukkan Jumlah Kolom A:");
System.out.println("Jumlah Ko4" + "lom A = " + Kolom_A);
System.out.println("\n");
String Baris_B = JOptionPane.showInputDialog("Masukkan Jumlah Baris B:");
System.out.println("Jumlah Baris B = " + Baris_B);
String Kolom_B = JOptionPane.showInputDialog("Masukkan Jumlah Kolom B:");
System.out.println("Jumlah Kolom B = " + Kolom_B);
System.out.println("\n" + "");
int Matrik_A[][] = new int[Integer.parseInt(Baris_A)][Integer.parseInt(Kolom_A)];
int Matrik_B[][] = new int[Integer.parseInt(Baris_B)][Integer.parseInt(Kolom_B)];
int hasil[][] = new int[3][3];
/* int A[][] = new int[3][3];
int B[][] = new int[3][3];
int hasil[][] = new int[3][3];*/
String dataA[][] = new String[3][3];
String dataB[][] = new String[3][3];
String hasil1[][] = new String[3][3];
int i = 0, j = 0, k = 0, m = 0;
// MATRIKS A
System.out.println("Elemen Matriks A adalah :");
do {
j = 0;
do {
dataA[i][j] = JOptionPane.showInputDialog(" Masukan data A [" + i + "][" + j + "]");
Matrik_A[i][j] = Integer.parseInt(dataA[i][j]);
j++;
} while (j < 3);
i++;
} while (i < 3);
// MATRIKS B
k = 0;
do {
m = 0;
do {
dataB[k][m] = JOptionPane.showInputDialog(" Masukan data B [" + k + "][" + m + "]");
Matrik_B[k][m] = Integer.parseInt(dataB[k][m]);
m++;
} while (m < 3);
k++;
} while (k < 3);
// Menampilkan data pada Matriks A
for (k = 0; k < 3; k++) {
for (m = 0; m < 3; m++) {
System.out.print(" " + Matrik_A[k][m]); // Menampilkan data A [i][j]
}
System.out.println();
}
System.out.println("\n");
System.out.println("Elemen Matriks B adalah :");
// Menampilkan data pada Matriks B
for (k = 0; k < 3; k++) {
for (m = 0; m < 3; m++) {
System.out.print(" " + Matrik_B[k][m]); // Menampilkan data B [k][m]
}
System.out.println();
}
// Uuntuk mengalikan dua matriks di atas
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
hasil[i][j] = 0;
for (k = 0; k < 3; k++) {
hasil[i][j] += Matrik_A[i][k] * Matrik_B[k][j];
}
}
}
System.out.println("\n\n");
System.out.println("Hasil dari perkalian dua matriks adalah = ");
// Untuk menampilkan hasil perkalian dua matriks
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
System.out.print(" " + hasil[i][j]);
}
System.out.println(" ");
}
System.out.println();
}
}
//import java.io.*;
import javax.swing.JOptionPane;
/**
* @author Muhammad Fairuz
*/
public class PERKALIAN_MATRIKS {
public static void main(String[] args) {
String Baris_A = JOptionPane.showInputDialog("Masukkan Jumlah Baris A:");
System.out.println("Jumlah Baris A = " + Baris_A);
String Kolom_A = JOptionPane.showInputDialog("Masukkan Jumlah Kolom A:");
System.out.println("Jumlah Ko4" + "lom A = " + Kolom_A);
System.out.println("\n");
String Baris_B = JOptionPane.showInputDialog("Masukkan Jumlah Baris B:");
System.out.println("Jumlah Baris B = " + Baris_B);
String Kolom_B = JOptionPane.showInputDialog("Masukkan Jumlah Kolom B:");
System.out.println("Jumlah Kolom B = " + Kolom_B);
System.out.println("\n" + "");
int Matrik_A[][] = new int[Integer.parseInt(Baris_A)][Integer.parseInt(Kolom_A)];
int Matrik_B[][] = new int[Integer.parseInt(Baris_B)][Integer.parseInt(Kolom_B)];
int hasil[][] = new int[3][3];
/* int A[][] = new int[3][3];
int B[][] = new int[3][3];
int hasil[][] = new int[3][3];*/
String dataA[][] = new String[3][3];
String dataB[][] = new String[3][3];
String hasil1[][] = new String[3][3];
int i = 0, j = 0, k = 0, m = 0;
// MATRIKS A
System.out.println("Elemen Matriks A adalah :");
do {
j = 0;
do {
dataA[i][j] = JOptionPane.showInputDialog(" Masukan data A [" + i + "][" + j + "]");
Matrik_A[i][j] = Integer.parseInt(dataA[i][j]);
j++;
} while (j < 3);
i++;
} while (i < 3);
// MATRIKS B
k = 0;
do {
m = 0;
do {
dataB[k][m] = JOptionPane.showInputDialog(" Masukan data B [" + k + "][" + m + "]");
Matrik_B[k][m] = Integer.parseInt(dataB[k][m]);
m++;
} while (m < 3);
k++;
} while (k < 3);
// Menampilkan data pada Matriks A
for (k = 0; k < 3; k++) {
for (m = 0; m < 3; m++) {
System.out.print(" " + Matrik_A[k][m]); // Menampilkan data A [i][j]
}
System.out.println();
}
System.out.println("\n");
System.out.println("Elemen Matriks B adalah :");
// Menampilkan data pada Matriks B
for (k = 0; k < 3; k++) {
for (m = 0; m < 3; m++) {
System.out.print(" " + Matrik_B[k][m]); // Menampilkan data B [k][m]
}
System.out.println();
}
// Uuntuk mengalikan dua matriks di atas
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
hasil[i][j] = 0;
for (k = 0; k < 3; k++) {
hasil[i][j] += Matrik_A[i][k] * Matrik_B[k][j];
}
}
}
System.out.println("\n\n");
System.out.println("Hasil dari perkalian dua matriks adalah = ");
// Untuk menampilkan hasil perkalian dua matriks
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
System.out.print(" " + hasil[i][j]);
}
System.out.println(" ");
}
System.out.println();
}
}
0 comments:
Posting Komentar