Hilfe auf Aufgabe(Matrixmultiplikation)

Q1yan

Neues Mitglied
Hallo,Leute

Ich habe eine Problem treffen,die Programm ist schon funktioniert,aber Ergebniss ist nicht richtig

Java:
public class Matrixmultiplikation{

    private static int[][] readMatrix(String[] input, int offset) {
        int i,j;
        int row = Integer.parseInt(input[offset]);
        int column = Integer.parseInt(input[offset+1]);
        int [][] m = new int [row][column];
        for (i=0;i<row;i++) {
            for (j=0;j<column;j++) {
                int zahl = Integer.parseInt(input[2+i*column+j]);
                m [i][j] = zahl;
            }
        }
      return m;
    }

    private static int[][] computeEntry(int[][] m1, int[][] m2, int row, int column) {
      int [][] m3 = null;
      int a,b,c;
      int sum = 0;
      int row1 = m1[0].length;
      int column1 = row;
      for (c=0;c<column;c++) {
        for (a=0;a<row1;a++) {
           m3 [][] = 0;
          for (b=0;b<column1;b++) {
              m3[a][c] += m1[a][b]*m2[b][c];
            }
          }
        }
      }
      return m3;
    }

    public static void main(String[] args) {
      int row1 = Integer.parseInt(args[0]);
      int column1 = Integer.parseInt(args[1]);
      int row2 = Integer.parseInt(args[2+row1*column1]);
      int column2 = Integer.parseInt(args[3+row1*column1]);
      int row3 = column1;
      int column3 = column2;
      String [] mat1= new String [args.length];
      String [] mat2= new String [args.length];
      int i,o;
      for (i=0;i<row1*column1+2;i++) {
        mat1 [i] = args[i];
      }
      for (i=0;i<row2*column2+2;i++) {
        mat2 [i] = args[row1*column1+2+i];
      }
      int m1 [][]  = readMatrix(mat1,0);
      int m2 [][]  = readMatrix(mat2,0);
      int m3 [][]  = computeEntry(m1,m2,row3,column3);
      for (i=0;i<row2;i++) {
        for (o=0;o<column2;o++) {
          System.out.print(m2[i][o]+" ");
          if (o+1==column2) {
            System.out.println("");
          }
        }
      }
    }
  }
 
Zuletzt bearbeitet von einem Moderator:
Ich habe vergesucht,nur die Matrix1 und Matrix2 als Output ausdrücken,aber habe ich auch keine richtige Ergebniss bekommt.Bedeutet das also,dass ReadMatrix Problem hat?
 

Neue Themen


Zurück
Oben