Sum of arrays in java matrix A + matrixB, results in matrix C

1

I need to do a matrix summation algorithm in Java, where the sum of the matrixA with the matrixB, generates the matrixC. so if matrixA has the same number of rows and columns as matrix B.

  

Calculate and show a resulting matrix C of the sum of matrix A with matrix B. It is only possible to add matrices if they are of the same order.

I really have no idea how to mount this arrayC, follow the code I've got so far.

public static void main(String[] args) {

    int N = Integer.parseInt(JOptionPane.showInputDialog("Digite o numero de linhas da A"));
    int M = Integer.parseInt(JOptionPane.showInputDialog("Digite o numero de colunas da A"));
    int O = Integer.parseInt(JOptionPane.showInputDialog("Digite o numero de linhas da B"));
    int P = Integer.parseInt(JOptionPane.showInputDialog("Digite o numero de colunas da B"));

    int matrizA[][] = new int[N][M];
    int matrizB[][] = new int[O][P];

    for (int i = 0; i < matrizA.length; i++) {
        for (int j = 0; j < matrizA.length; j++) {

            matrizA[i][j] = Integer.parseInt(JOptionPane.showInputDialog("Digite o " + (i + 1) + " valor da matriz A"));

        }

    }
    for (int i = 0; i < matrizB.length; i++) {
        for (int j = 0; j < matrizB.length; j++) {

            matrizB[i][j] = Integer.parseInt(JOptionPane.showInputDialog("Digite o " + (j + 1) + " valor da matriz B"));
        }

    }

    int soma = 0;

    if (N == O && M == P) {

        for (int i = 0; i < matrizB.length; i++) {
            for (int j = 0; j < matrizB.length; j++) {

                soma = matrizA[i][j] + matrizB[i][j];

            }

        }

    }
    
asked by anonymous 10.09.2017 / 22:52

0 answers