import java.io.*;
class transpose3
{
public static void main (String []args) throws IOException
{
BufferedReader input = new BufferedReader ( new InputStreamReader (System.in));
//Deklarasi Input dari class BufferedReader
System.out.print("masukkan jumlah ordo matriks n*n = ");
int n=Integer.parseInt(input.readLine ());
int [][] matriksA = new int [n][n];
int [][] matriksB = new int [n][n];
int [][] matriksC = new int [n][n];(1)
//Deklarasi variable yang digunakan
System.out.println("Matriks A = " );
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)(2)
{
System.out.print("Elemen ["+(i+1)+","+(j+1)+"]=");
matriksA[i][j]=Integer.parseInt(input.readLine()); //Input matriks A kedalam variable matriks (3)
}
}
System.out.println("Matriks B = " );
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print("Elemen ["+(i+1)+","+(j+1)+"]="); (4)
matriksB[i][j]=Integer.parseInt(input.readLine());
}
}
System.out.print("");
for(int i=0;i<n;i++)
{
System.out.print("|");
for(int j=0;j<n;j++)
{
matriksC[i][j]=matriksA[i][j]+matriksB[i][j]; (5)
System.out.print(matriksC[i][j]+" ");
}
System.out.println("|");
}
System.out.print("]");
}
}
Like this:
Like Loading...
Related