Untitled
Never
import java.util.Scanner; public class sumofarr { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter the number of rows: "); int rows = sc.nextInt(); System.out.print("Enter the number of columns: "); int columns = sc.nextInt(); double[][] matrix1 = new double[rows][columns]; System.out.println("Enter the elements of the first matrix:"); for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { matrix1[i][j] = sc.nextDouble(); } } double[][] matrix2 = new double[rows][columns]; System.out.println("Enter the elements of the second matrix:"); for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { matrix2[i][j] = sc.nextDouble(); } } double[][] resultMatrix = new double[rows][columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { resultMatrix[i][j] = matrix1[i][j] + matrix2[i][j]; } } System.out.println("The sum of the two matrices is:"); for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { System.out.print(resultMatrix[i][j] + " "); } System.out.println(); } } }