package lat_matrikskali_sitimadinah;
/* @author Ahmad Firdausi */
import java.io.*;
public class Main {
/* @param args the command line arguments */
public static void main(String[] args) {
// TODO code application logic here
DataInputStream entry = new DataInputStream(System.in);
try
{
System.out.print(" INPUT JUMLAH BARIS MATRIKS 1 = ");
int JmlBrs1 = Integer.parseInt(entry.readLine());
System.out.print(" INPUT JUMLAH KOLOM MATRIKS 1 = ");
int JmlKlm1 = Integer.parseInt(entry.readLine());
int JmlBrs2 = JmlKlm1;
System.out.print(" INPUT JUMLAH KOLOM MATRIKS 2 = ");
int JmlKlm2 = Integer.parseInt(entry.readLine());
int [][] MatriksA = new int[JmlBrs1][JmlKlm1];
int [][] MatriksB = new int[JmlBrs2][JmlKlm2];
int [][] MatriksC = new int[JmlBrs1][JmlKlm2];
for (int i=0; i<JmlBrs1; i++)
for (int j=0; j<JmlKlm1; j++)
MatriksA[i][j] = (int)(Math.random()*100);
for (int i=0; i<JmlBrs2; i++)
for (int j=0; j<JmlKlm2; j++)
MatriksB[i][j] = (int)(Math.random()*100);
for (int i=0; i<JmlBrs1; i++)
for (int j=0; j<JmlKlm2; j++)
{
MatriksC[i][j] = 0;
for (int k=0; k<JmlKlm1; k++)
MatriksC[i][j] += MatriksA[i][k] * MatriksB[k][j];
}
System.out.println(" \n DATA MATRIKS A = ");
System.out.println("______________________");
for (int i=0; i<JmlBrs1; i++)
{
for (int j=0; j<JmlKlm1; j++)
System.out.print(MatriksA[i][j] + " ");
System.out.println();
}
System.out.println(" \n DATA MATRIKS B = ");
System.out.println("______________________");
for (int i=0; i<JmlBrs2; i++)
{
for (int j=0; j<JmlKlm2; j++)
System.out.print(MatriksB[i][j] + " ");
System.out.println();
}
System.out.println(" \n MATRIKS " + " PERKALIAN A x B = ");
System.out.println("_________________" + "_______________");
for (int i=0; i<JmlBrs1; i++)
{
for (int j=0; j<JmlKlm2; j++)
System.out.print(MatriksC[i][j] + " ");
System.out.println();
}
}
catch (Exception e)
{
System.out.println(" SALAH ENTRY DATA ");
}
}
}
0 komentar:
Posting Komentar