PROGRAM
import java.io.*;
public class Matriks {
public static void main(String[] args)
throws IOException {
int a1,a2,a3,a4,b1,b2,b3,b4,b5,b6,c1,c2,c3,c4,c5,c6;
BufferedReader br = new
BufferedReader(new InputStreamReader(System.in));
try {
System.out.println("Matriks Perkalian Ordo 2x2 dan 2x3
");
System.out.println();
System.out.println("Matriks A");
System.out.print("Masukan
Elemen 1,1 : ");
a1=
Integer.parseInt(br.readLine());
//mengkonversi nilai kedalam
bentuk integer
System.out.print("Masukan
Elemen 1,2 : ");
a2=
Integer.parseInt(br.readLine());
System.out.print("Masukan
Elemen 2,1 : ");
a3=
Integer.parseInt(br.readLine());
System.out.print("Masukan Elemen 2,2
: ");
a4=
Integer.parseInt(br.readLine());
System.out.println();
System.out.println("Matriks B");
System.out.print("Masukan
Elemen 1,1 : ");
b1=
Integer.parseInt(br.readLine());
System.out.print("Masukan
Elemen 1,2 : ");
b2=
Integer.parseInt(br.readLine());
System.out.print("Masukan
Elemen 2,1 : ");
b3= Integer.parseInt(br.readLine());
System.out.print("Masukan
Elemen 2,2 : ");
b4=
Integer.parseInt(br.readLine());
System.out.print("Masukan
Elemen 3,1 : ");
b5= Integer.parseInt(br.readLine());
System.out.print("Masukan
Elemen 3,2 : ");
b6=
Integer.parseInt(br.readLine());
c1=(a1*b1)+(a2*b4); //perkalian
nilai matriks
c2=(a1*b2)+(a2*b5);
c3=(a1*b3)+(a2*b6);
c4=(a3*b1)+(a4*b4);
c5=(a3*b2)+(a4*b5);
c6=(a3*b3)+(a4*b6);
System.out.println();
System.out.println("Hasil
Matriks :");
System.out.println(" "+c1+" "+c2+" "+c3);
System.out.println();
System.out.println(" " +c4+" "+c5+" "+c6);
}
catch(Exception e) {
System.out.println("Error
: " + e);
}
}
}
OUTPUT PROGRAM
Tidak ada komentar:
Posting Komentar