Estou tentando rodar este código, porém não há retorno compatível na função Multiplicar a matriz (O valor devolvido não bate com o calculo real).
Tem como dar um Help? Já procurei em demais tópicos e estou utilizando sintáxe parecida com os demais.
Att.
package teste;
import java.util.Scanner;
/**
*
* @author wnx
*
*/
public class Teste {
public static void main(String[] args) {
//Declaração de variáveis
int lerDados;
int qtdCol;
//Instruções de menu:
Scanner s = new Scanner(System.in);
System.out.println(" *** SISTEMA DE CÁLCULO DE MATRIZES *** ");
System.out.println("");
System.out.println("MENU DE OPÇÕES: ");
System.out.println("");
System.out.println("1 - Inserir inserir informações sobre as Matrizes A e B");
System.out.println("0 - Finalizar aplicação");
//System.out.println("4 - Solicitar multiplicação entre as Matrizes");*/
System.out.println("");
//Leitura de dados Menu
System.out.print("Informe a opção desejada: ");
lerDados = s.nextInt();
System.out.println("Trabalharemos com matrizes quadradas"
+ " informe a quantidade de Linhas: ");
qtdCol = s.nextInt();
System.out.println("");
System.out.println("As matrizes terão " + qtdCol + " linhas e " + qtdCol
+ " colunas.");
//Declaração de Matriz
int[][] matriz1 = new int[qtdCol][qtdCol];
int[][] matriz2 = new int[qtdCol][qtdCol];
int[][] mtResultante = new int[matriz1.length][matriz2[0].length];
int[][] mtResultanteX = new int[matriz1.length][matriz2[0].length];
if (lerDados == 1) {
System.out.println("");
System.out.println("Insira os valores da Matriz A");
System.out.println("");
for (int x = 0; x < matriz1.length; x++) {
for (int y = 0; y < matriz1.length; y++) {
System.out.println("Informe o valor da posição " + (y + 1)
+ " da linha " + (x + 1));
matriz1[x][y] = s.nextInt();
}
}
//Impressão de Matrizes
for (int l = 0; l < matriz1.length; l++) {
for (int a = 0; a < matriz1.length; a++) {
System.out.print(matriz1[l][a] + " ");
}
System.out.println("");
}
System.out.println("");
System.out.println("Insira os valores da Matriz B");
System.out.println("");
for (int x = 0; x < matriz2.length; x++) {
for (int y = 0; y < matriz2.length; y++) {
System.out.println("Informe o valor da posição " + (y + 1)
+ " da linha " + (x + 1));
matriz2[x][y] = s.nextInt();
}
}
//Impressão de Matrizes
for (int l = 0; l < matriz2.length; l++) {
for (int a = 0; a < matriz2.length; a++) {
System.out.print(matriz2[l][a] + " ");
}
System.out.println("");
}
System.out.println("Matriz Resultante da Operação SOMA:");
for (int r = 0; r < mtResultante.length; r++) {
for (int x = 0; x < matriz1.length; x++) {
for (int y = 0; y < matriz2.length; y++) {
mtResultante[x][y] = (matriz1[x][y] + matriz2[x][y]);
}
}
}
//Impressão de Matrizes
for (int l = 0; l < mtResultante.length; l++) {
for (int a = 0; a < mtResultante.length; a++) {
System.out.print(mtResultante[l][a] + " ");
}
System.out.println("");
}
System.out.println("Matriz Resultante da Operação MULTIPLICAÇÃO (Produto)");
int somase = 0;
for (int r = 0; r < mtResultanteX.length; r++) {
for (int x = 0; x < mtResultanteX.length; x++) {
for (int y = 0; y < mtResultanteX.length; y++) {
mtResultanteX[r][x] = mtResultanteX[r][x] + matriz1[x][y] * matriz2[x][y];
}
System.out.println("Linha: " + (r + 1) + " Coluna: "
+ (x + 1) + " = " + mtResultanteX[r][x]);
}
}
//Impressão de Matrizes
for (int l = 0; l < mtResultanteX.length; l++) {
for (int a = 0; a < mtResultanteX.length; a++) {
System.out.print(mtResultanteX[l][a] + " ");
}
System.out.println("");
}
}
if (lerDados == 0) {
System.out.println("");
System.out.println("Obrigado por utilizar nossa aplicação. Volte sempre!");
System.out.println("");
System.exit(0);
}
}
}