import java.util.Scanner; /** * Read two matrixes from standard input and print * the sum of both if they match their size */ public class Solution { /** * Gets data from standard input */ private Scanner input = null; /** * Start the execution of the solution * @param args Command line arguments */ public static void main(String args[]) { Solution solution = new Solution(); solution.run(); } /** * Run the solution. This method is called from main() */ public void run() { // Create object to read data from standard input input = new Scanner(System.in); // Read a matrix from standard input Matrix matrix1 = new Matrix(); matrix1.read(input); // Read a second matrix from standard input Matrix matrix2 = new Matrix(); matrix2.read(input); // Try to add both matrixes Matrix sum = matrix1.add(matrix2); // If both matrixes were added, we got an object reference if ( sum != null ) { // Print the resulting sum sum.print(System.out); } else { // Matrixes do not match their dimensions System.out.println("Matrices must match size to be added"); } // Close the standard input input.close(); } }