57. Matrix Subtraction. import java.util.Scanner; class Matrix_Subtraction { Scanner scan; int matrix1[][], matrix2[][], sub[][]; int row, column; void create() { scan = new Scanner(System.in); System.out.println("Matrix Subtraction"); // First Matrix Creation.. System.out.println(" Enter number of rows & columns"); row = Integer.parseInt(scan.nextLine()); column = Integer.parseInt(scan.nextLine()); matrix1 = new int[row][column]; matrix2 = new int[row][column]; sub = new int[row][column]; System.out.println("Enter the data for first matrix :"); for(int i=0; i &lt row; i++) { for(int j=0; j &lt column; j++) { matrix1[i][j] = scan.nextInt(); } } // Second Matrix Creation.. System.out.println("Enter the data for second matrix :"); for(int i=0; i &lt row; i++) { for(int j=0; j &lt column; j++) { matrix2[i][j] = scan.nextInt(); } } } void display() { System.out.println(" The First Matrix is :"); for(int i=0; i &lt row; i++) { for(int j=0; j &lt column; j++) { System.out.print(" " + matrix1[i][j]); } System.out.println(); } System.out.println(" The Second Matrix is :"); for(int i=0; i &lt row; i++) { for(int j=0; j &lt column; j++) { System.out.print(" " + matrix2[i][j]); } System.out.println(); } } void sub() { for(int i=0; i &lt row; i++) { for(int j=0; j &lt column; j++) { sub[i][j] = matrix1[i][j] - matrix2[i][j]; } } System.out.println(" The Subtraction is :"); for(int i=0; i &lt row; i++) { for(int j=0; j &lt column; j++) { System.out.print(" " + sub[i][j]); } System.out.println(); } } } class MatrixSubtractionExample { public static void main(String args[]) { Matrix_Subtraction obj = new Matrix_Subtraction(); obj.create(); obj.display(); obj.sub(); } } @java_codings 14.1K viewsSuthar Pravin, 03:53