Addition of two Matrics in JAVA Programming



//Addition of two Matrics in JAVA



package SolveProblem;

import java.util.Scanner;

import javax.management.relation.RoleUnresolved;

public class AddTwoMatrics {

    public static void main(String[] args) {
        Scanner myScanner=new Scanner(System.in);
       
        int row,column;
       
        System.out.println("Enter the value of Row & Column : ");
       
        row=myScanner.nextInt();
        column=myScanner.nextInt();
        int[][] first=new int[row][column];
        int[][] second=new int[row][column];
        int[][] result=new int[row][column];
        System.out.println("Enter first matrics : ");
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < column; j++) {
                first[i][j]=myScanner.nextInt();
            }
        }
        System.out.println("Enter second Matrics : ");

        for (int i = 0; i < row; i++) {
            for (int j = 0; j < column; j++) {
                second[i][j]=myScanner.nextInt();
            }
        }

        for (int i = 0; i < row; i++) {
            for (int j = 0; j < column; j++) {
                result[i][j]=first[i][j]+second[i][j];
            }
        }
       
         System.out.println("Addition of two matrics is : ");
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < column; j++) {
                System.out.print(result[i][j]+"\t");
               
            }
            System.out.println();
        }
    }

}

No comments:

Post a Comment