/* *Com S 207 *Hw 7 *Matrix.java * *Thanks to Jacob Burgduff. */ import java.util.Scanner; public class Matricies { public static void main (String[] args) { double [][] A = new double [3][3]; double [][] B = new double [3][3]; double [][] C = new double [3][3]; double [][] Temp = new double [3][3]; double [][] Result = new double [3][3]; Scanner scan = new Scanner(System.in); //Prompt user to input the values for the matricies System.out.println("Please enter the values for the A matrix: "); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { A[i][j] = scan.nextDouble(); } } //Print the array System.out.println("The Matrix A you entered is: "); for(int i = 0; i < 3; i++) { System.out.println(); for (int j = 0; j < 3; j++) { System.out.print(A[i][j] + " "); } } System.out.println(); System.out.println("Please enter the values for the B matrix: "); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { B[i][j] = scan.nextDouble(); } } //Print the array System.out.println("The Matrix B you entered is: "); for(int i = 0; i < 3; i++) { System.out.println(); for (int j = 0; j < 3; j++) { System.out.print(B[i][j] + " "); } } System.out.println(); System.out.println("Please enter the values for the C matrix: "); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { C[i][j] = scan.nextDouble(); } } //Print the array System.out.println("The Matrix C you entered is: "); for(int i = 0; i < 3; i++) { System.out.println(); for (int j = 0; j < 3; j++) { System.out.print(C[i][j] + " "); } } //Add matrix A and B together and store in Temp for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { Temp[i][j] = A[i][j] + B[i][j]; } } //Print the Temp array for verification System.out.println(); System.out.println("The Temp Matrix is: "); for(int i = 0; i < 3; i++) { System.out.println(); for (int j = 0; j < 3; j++) { System.out.print(Temp[i][j] + " "); } } //Multiply Temp with matrix C to get the Result matrix for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) for (int k = 0; k < 3; k++) Result[i][k] += Temp[i][j] * C[j][k]; //Print the Result matrix System.out.println(); System.out.println("The Result Matrix is: "); for(int i = 0; i < 3; i++) { System.out.println(); for (int j = 0; j < 3; j++) { System.out.print(Result[i][j] + " "); } } } }