import java.util.Scanner; public class Addition { public static void main(String args[]) { int i, j; int matrix1[][] = new int[3][3]; int matrix2[][] = new int[3][3]; int matrix3[][] = new int[3][3]; Scanner scan = new Scanner(System.in); System.out.print("Enter Matrix Elements : "); for(i=0; i<3; i++) { for(j=0; j<3; j++) { matrix1[i][j] = scan.nextInt(); } } System.out.print("Enter Matrix Elements : "); for(i=0; i<3; i++) { for(j=0; j<3; j++) { matrix2[i][j] = scan.nextInt(); } } System.out.print("Adding both Matrix to form the Third Matrix...\n"); for(i=0; i<3; i++) { for(j=0; j<3; j++) { matrix3[i][j] = matrix1[i][j] + matrix2[i][j]; } } System.out.print("Matrix after addition will be :\n"); for(i=0; i<3; i++) { for(j=0; j<3; j++) { System.out.print(matrix3[i][j]+ " "); } System.out.println(); } } }
Monday, 6 November 2017
Java Program to add 2 matrices of size 3
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment