earlution

Stage 1/6: Addition - Main

Mar 30th, 2021 (edited)
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. package processor;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int n; //rows
  9.         int m; //columns
  10.  
  11.         //capture matrixA
  12.         n = scanner.nextInt();
  13.         m = scanner.nextInt();
  14.         Matrix matrixA = new Matrix(n, m); //define empty matrix with correct dimensions
  15.         matrixA.readMatrix();
  16.         //matrixA.print(); //test matrixA
  17.  
  18.         //capture matrixB
  19.         n = scanner.nextInt();
  20.         m = scanner.nextInt();
  21.         Matrix matrixB = new Matrix(n, m);
  22.         matrixB.readMatrix();
  23.         /* matrixB.print(); //test matrixB */
  24.  
  25.         if (matrixA.rows != matrixB.rows && matrixA.columns != matrixB.columns) {
  26.             System.out.println("ERROR");
  27.         } else {
  28.             Matrix matrixC = matrixA.addMatrix(matrixB);
  29.             matrixC.printMatrix();
  30.         }
  31.     }
  32. }
  33.  
Add Comment
Please, Sign In to add comment