class array2D
{
public static void main(String[]args)throws Exception
{
DataInputStream p = new DataInputStream(System.in);
{
System.out.print("inputkan kolom = ");
int x = Integer.parseInt(p.readLine());
System.out.print("inputkan baris = ");
int y = Integer.parseInt(p.readLine());
int A[][] = new int [y][x];
int B[][] = new int [y][x];
int C[][] = new int [y][x];
int D[][] = new int [y][x];
int F[][] = new int [y][x];
for(int i = 0;i<y;i++)
{
for(int j = 0;j<x;j++)
{
System.out.print("a"+(i+1)+(j+1)+"=");
A[i][j] = Integer.parseInt(p.readLine());
}
}
for(int g = 0;g<y;g++)
{
for(int h=0;h<x;h++)
{
System.out.print("b"+(g+1)+(h+1)+"=");
B[g][h] = Integer.parseInt(p.readLine());
}
}
System.out.println("Tampil Matriks ke Bawah");
System.out.println("Matriks A");
for(int l=0;l<y;l++)
{
for(int m=0;m<x;m++)
{
System.out.println(A[l][m]+" ");
}
System.out.println();
}
System.out.println();
System.out.println("Matriks B");
for(int ww=0;ww<y;ww++)
{
for(int qq=0;qq<x;qq++)
{
System.out.println(B[ww][qq]+" ");
}
}
System.out.println("Tampil Matriks Bentuk Asli");
for(int d=0;d<y;d++)
{
for(int f=0;f<x;f++)
{
System.out.print(A[d][f]+" ");
}
System.out.println();
}
System.out.println();
for(int uu=0;uu<y;uu++)
{
for(int ii=0;ii<x;ii++)
{
System.out.print(B[uu][ii]+" ");
}
System.out.println();
}
System.out.println();
System.out.println("Hasil Penjumlahan");
for(int hh=0;hh<y;hh++)
{
for(int jj=0;jj<x;jj++)
{
C[hh][jj]=A[hh][jj]+B[hh][jj];
System.out.print(C[hh][jj]+" ");
}
System.out.println();
}
System.out.println();
System.out.println("Hasil Pengurangan");
for(int ggg=0;ggg<y;ggg++)
{
for(int uuu=0;uuu<x;uuu++)
{
D[ggg][uuu]=A[ggg][uuu]-B[ggg][uuu];
System.out.print(D[ggg][uuu]+" ");
}
System.out.println();
}
System.out.println();
System.out.println("Hasil Perkalian");
if(x==y)
{
for(int hhh=0;hhh<y;hhh++)
{
for(int ggg=0;ggg<x;ggg++)
{
F[hhh][ggg]=0;
for(int iii=0;iii<y;iii++)
{
int jum=A[ggg][iii]*B[iii][hhh];
F[hhh][ggg]=F[hhh][ggg]+jum;
}
}
}
for (int zx=0;zx<y;zx++ )
{
for (int xz=0;xz<x ;xz++ )
{
System.out.print(F[xz][zx]+" ");
}
System.out.println();
}
}
else
{
System.out.println("Hahhhhh");
}
}
}
}
Tidak ada komentar:
Posting Komentar