AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
3. Our Experts are looking for yours ?.

# corejava-programming: calculate the addition and subtraction of two given matrices

 Write a Program to calculate the addition and subtraction of two given matrices(3x3). Input Specification: Input will be two matrices each 3x3 order Output Specification: Your Program should print two 3x3 matrices with first matrix Representing the sum and the next matrix representing the difference Of those two matrices. Print an empty line between the matrices. Sample Input: 1 2 3 4 5 6 7 8 9 5 4 3 6 7 2 5 4 5 Sample Output: 6 6 6 10 12 8 12 12 14 -4 -2 0 -2 -2 4 2 4 4 corejava x 353programming x 169 Posted On : 2016-07-13 17:37:16.0 Boopalan 3730 4

 import java.util.Scanner; public class MainClass { public static void main(String args[]) { Matrix obj = new Matrix(); obj.create(); obj.display(); obj.add(); } } class Matrix { int row, column; int matrix1[][], matrix2[][], sum[][]; void create() { Scanner sc= new Scanner(System.in); System.out.println("Matrix Addition"); // 1st matrix creation System.out.println("\nEnter number of rows & columns"); row = Integer.parseInt(sc.nextLine()); column = Integer.parseInt(sc.nextLine()); matrix1 = new int[row][column]; matrix2 = new int[row][column]; sum = new int[row][column]; System.out.println("Enter the data for 1st matrix :"); for(int i=0; i
Incomplete solution, and as per the requirement no need to print input matrices.
Rishi Kumar
523  1882  31239
Posted On :2016-07-18 17:58:53.0

 import java.util.*; import java.io.*; public class Matrix { public static void main(String[] ar)throws IOException { int m1[][] = new int[5][5]; int m2[][] = new int[5][5]; int m3[][] = new int[5][5]; Scanner sc = new Scanner(System.in); System.out.print("Number of row: "); int row = sc.nextInt(); System.out.print("Number of column: "); int col = sc.nextInt(); System.out.println(); for(int i=0; i
Ohh.. Here you again posted the answer with full solution. But the input taking strategy is quite good in first answer.
Rishi Kumar
523  1882  31239
Posted On :2016-07-18 18:03:24.0

 import java.util.Scanner; class SumSubmatrices { public static void main(String args[]) { Scanner s=new Scanner(System.in); int[][] mat1=new int[3][3]; int[][] mat2=new int[3][3]; int[][] mat3=new int[3][3]; for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { mat1[i][j]=s.nextInt(); } System.out.println(); } for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { mat2[i][j]=s.nextInt(); } System.out.println(); } System.out.println("::Output::"); for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { mat3[i][j]=mat1[i][j]+mat2[i][j]; System.out.print(mat3[i][j]+" "); } System.out.println(); } System.out.println(" "); for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { mat3[i][j]=mat1[i][j]-mat2[i][j]; System.out.print(mat3[i][j]+" "); } System.out.println(); } } } Posted On : 2016-07-18 17:05:18 Satisfied : 2 Yes  0 No 5