import java.io.*;
class matrixx{
public static void main(String[] args)throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int[][] matA = new int[3][4];
int[][] matB = new int[4][3];
int[][] matC = new int[3][3];
int A,B;
for(int i=0;i<3;i++) {
for(int j=0;j<4;j++) {
System.out.print("A("+(i+1)+","+(j+1)+"): ");
A=Integer.parseInt(br.readLine());
matA[i][j]=A;
}
System.out.println();
}
for(int i=0;i<4;i++) {
for(int j=0;j<3;j++) {
System.out.print("B("+(i+1)+","+(j+1)+"): ");
B=Integer.parseInt(br.readLine());
matB[i][j]=B;
}
System.out.println();
}
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
matC[i][j]=0;
for(int n=0;n<4;n++)
{
matC[i][j]=matC[i][j]+matA[i][n]*matB[n][j];
}
}
}
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.println("C("+(i+1)+","+(j+1)+"): "+matC[i][j]);
}
System.out.println();
}
//simpan
try{
File x = new File("d:\\Mat_A.txt");
PrintWriter adj=new PrintWriter(new FileWriter(x.getPath()));
adj.print(matA[0][0]+"$");
adj.print(matA[0][1]+"$");
adj.print(matA[0][2]+"$");
adj.println(matA[0][3]+"#");
adj.print(matA[1][0]+"$");
adj.print(matA[1][1]+"$");
adj.print(matA[1][2]+"$");
adj.println(matA[1][3]+"#");
adj.print(matA[2][0]+"$");
adj.print(matA[2][1]+"$");
adj.print(matA[2][2]+"$");
adj.println(matA[2][3]+"^");
File y = new File("d:\\Mat_B.txt");
PrintWriter adj1=new PrintWriter(new FileWriter(y.getPath()));
adj1.print(matB[0][0]+"$");
adj1.print(matB[0][1]+"$");
adj1.println(matB[0][2]+"#");
adj1.print(matB[1][0]+"$");
adj1.print(matB[1][1]+"$");
adj1.println(matB[1][2]+"#");
adj1.print(matB[2][0]+"$");
adj1.print(matB[2][1]+"$");
adj1.println(matB[2][2]+"#");
adj1.print(matB[3][0]+"$");
adj1.print(matB[3][1]+"$");
adj1.println(matB[3][2]+"#");
File z = new File("d:\\Mat_C.txt");
PrintWriter adj2=new PrintWriter(new FileWriter(z.getPath()));
adj2.print(matC[0][0]+"$");
adj2.print(matC[0][1]+"$");
adj2.println(matC[0][2]+"#");
adj2.print(matC[1][0]+"$");
adj2.print(matC[1][1]+"$");
adj2.println(matC[1][2]+"#");
adj2.print(matC[2][0]+"$");
adj2.print(matC[2][1]+"$");
adj2.println(matC[2][2]+"^");
adj.close();
adj1.close();
adj2.close();
}catch(IOException e){ }
}
}
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar