import javax.swing.*; //Menggunakan method javax swing untuk menginput nilai matriks melalui kotak dialog
public class matrikk //nama kelas program
{
public static void main(String[]args) throws Exception //program main(utama)
{
//Mendeklarasikan baris, kolom, dan nilai skalar dengan menggunakan input dialog
int b=Integer.parseInt(JOptionPane.showInputDialog("Masukkan banyaknya baris: ","2"));
int k=Integer.parseInt(JOptionPane.showInputDialog("Masukkan banyaknya kolom: ","2"));
int skalar=Integer.parseInt(JOptionPane.showInputDialog("Masukkan Nilai Skalar: ","2"));
// Memasukkan nilai matrik A dengan menggunakan input dialog
System.out.print("Matriks A: \n");
int A[][]=new int [b][k];
for (int i=0;i
{
System.out.print("|");
for (int j=0;j< k;j++)
{
A[i][j]=Integer.parseInt(JOptionPane.showInputDialog("Matrik A ["+(i+1)+"]["+(j+1)+"]="));
System.out.print(" "+A[i][j]+" ");
}
System.out.println("|");
}
System.out.println();
// Memasukkan nilai matrik B dengan menggunakan input dialog
System.out.print("Matriks B: \n");
int B[][]=new int [b][k];
for (int i=0;i
{
System.out.print("|");
for (int j=0;j
{
B[i][j]=Integer.parseInt(JOptionPane.showInputDialog("Matrik B ["+(i+1)+"]["+(j+1)+"]="));
System.out.print(" "+B[i][j]+" ");
}
System.out.println("|");
}
System.out.println();
System.out.println("PENJUMLAHAN MATRIK");
for (int i=0;i
{
System.out.print("|");
for (int j=0;j
{
System.out.print(" "+A[i][j]+B[i][j]+" ");
}
System.out.println("|");
}
System.out.println();
System.out.println("PENGURANGAN MATRIK");
for (int i=0;i
{
System.out.print("|");
for (int j=0;j
{
System.out.print(" "+(A[i][j]-B[i][j])+" ");
}
System.out.println("|");
}
System.out.println();
// Mendeklarasikan perkalian matrik A dengan Matrik B
int C[][]=new int [b][k];
C[0][0]=(A[0][0]*B[0][0])+(A[0][1]*B[1][0]);
C[0][1]=(A[0][0]*B[0][1])+(A[0][1]*B[1][1]);
C[1][0]=(A[1][0]*B[0][0])+(A[1][1]*B[1][0]);
C[1][1]=(A[1][0]*B[0][1])+(A[1][1]*B[1][1]);
System.out.println("PERKALIAN MATRIK");
for (int i=0;i
{
System.out.print("|");
for (int j=0;j
{
System.out.print(" "+C[i][j]+" ");
}
System.out.println("|");
}
System.out.println();
System.out.println("PERKALIAN SKALAR MATRIK");
for(int i=0;i
{
System.out.print("|");
for(int j=0;j
{
System.out.print(" "+(skalar*A[i][j]+skalar*B[i][j])+" ");
}
System.out.println("|");
}
System.out.println("\n");
}
}
public class matrikk //nama kelas program
{
public static void main(String[]args) throws Exception //program main(utama)
{
//Mendeklarasikan baris, kolom, dan nilai skalar dengan menggunakan input dialog
int b=Integer.parseInt(JOptionPane.showInputDialog("Masukkan banyaknya baris: ","2"));
int k=Integer.parseInt(JOptionPane.showInputDialog("Masukkan banyaknya kolom: ","2"));
int skalar=Integer.parseInt(JOptionPane.showInputDialog("Masukkan Nilai Skalar: ","2"));
// Memasukkan nilai matrik A dengan menggunakan input dialog
System.out.print("Matriks A: \n");
int A[][]=new int [b][k];
for (int i=0;i
{
System.out.print("|");
for (int j=0;j< k;j++)
{
A[i][j]=Integer.parseInt(JOptionPane.showInputDialog("Matrik A ["+(i+1)+"]["+(j+1)+"]="));
System.out.print(" "+A[i][j]+" ");
}
System.out.println("|");
}
System.out.println();
// Memasukkan nilai matrik B dengan menggunakan input dialog
System.out.print("Matriks B: \n");
int B[][]=new int [b][k];
for (int i=0;i
{
System.out.print("|");
for (int j=0;j
{
B[i][j]=Integer.parseInt(JOptionPane.showInputDialog("Matrik B ["+(i+1)+"]["+(j+1)+"]="));
System.out.print(" "+B[i][j]+" ");
}
System.out.println("|");
}
System.out.println();
System.out.println("PENJUMLAHAN MATRIK");
for (int i=0;i
{
System.out.print("|");
for (int j=0;j
{
System.out.print(" "+A[i][j]+B[i][j]+" ");
}
System.out.println("|");
}
System.out.println();
System.out.println("PENGURANGAN MATRIK");
for (int i=0;i
{
System.out.print("|");
for (int j=0;j
{
System.out.print(" "+(A[i][j]-B[i][j])+" ");
}
System.out.println("|");
}
System.out.println();
// Mendeklarasikan perkalian matrik A dengan Matrik B
int C[][]=new int [b][k];
C[0][0]=(A[0][0]*B[0][0])+(A[0][1]*B[1][0]);
C[0][1]=(A[0][0]*B[0][1])+(A[0][1]*B[1][1]);
C[1][0]=(A[1][0]*B[0][0])+(A[1][1]*B[1][0]);
C[1][1]=(A[1][0]*B[0][1])+(A[1][1]*B[1][1]);
System.out.println("PERKALIAN MATRIK");
for (int i=0;i
{
System.out.print("|");
for (int j=0;j
{
System.out.print(" "+C[i][j]+" ");
}
System.out.println("|");
}
System.out.println();
System.out.println("PERKALIAN SKALAR MATRIK");
for(int i=0;i
{
System.out.print("|");
for(int j=0;j
{
System.out.print(" "+(skalar*A[i][j]+skalar*B[i][j])+" ");
}
System.out.println("|");
}
System.out.println("\n");
}
}