add two matrices in java using bufferedreader

Solutions on MaxInterview for add two matrices in java using bufferedreader by the best coders in the world

showing results for - "add two matrices in java using bufferedreader"
Jorge
06 May 2020
1// Add two matrices in java using bufferedreader
2import java.io.BufferedReader;
3import java.io.IOException;
4import java.io.InputStreamReader;
5public class AddTwoMatrixUsingBufferedReader
6{
7   public static void main(String[] args) throws NumberFormatException, IOException
8   {
9      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10      int a, b;
11      int[][] arr1 = new int[2][2];
12      int[][] arr2 = new int[2][2];
13      int[][] addition = new int[2][2];
14      System.out.println("Please enter elements of first matrix: ");
15      for(a = 0; a < 2; a++)
16      {
17         for(b = 0; b < 2; b++)
18         {
19            arr1[a][b] = Integer.parseInt(br.readLine());
20         }
21      }
22      System.out.println("Please enter elements of second matrix: ");
23      for(a = 0; a < 2; a++)
24      {
25         for(b = 0; b < 2; b++)
26         {
27            arr2[a][b] = Integer.parseInt(br.readLine());
28         }
29      }
30      System.out.println("Addition of two matrix in java using bufferedreader: ");
31      for(a = 0; a < 2; a++)
32      {
33         for(b = 0; b < 2; b++)
34         {
35            addition[a][b] = arr1[a][b] + arr2[a][b];
36            System.out.print(" " + addition[a][b]);
37         }
38         System.out.println( );
39      }
40   }
41}