Morgen 
Ich hab ein Problem bei dem ich einfach nicht weiter komme.
Ich soll eine 3x3 Matrix Multiplizieren und in eine neue Array speichern.
Der Code war soweit vorgegeben und kann nicht verändert werden nur die Methode sollte ich schreiben.
Und hier kommt mein Problem:
Ich habe zwei Arrays vom Typ double. Meine Methode klappt soweit nur das sie statt double einen int wert zurück gibt. Wie löse ich das?
Code ist wie folgt:

Ich hab ein Problem bei dem ich einfach nicht weiter komme.
Ich soll eine 3x3 Matrix Multiplizieren und in eine neue Array speichern.
Der Code war soweit vorgegeben und kann nicht verändert werden nur die Methode sollte ich schreiben.
Und hier kommt mein Problem:
Ich habe zwei Arrays vom Typ double. Meine Methode klappt soweit nur das sie statt double einen int wert zurück gibt. Wie löse ich das?
Code ist wie folgt:
Java:
public class MatrixMultiplication3x3 {
public static double[][] mult3x3(double[][] A, double[][] B) {
if (A.length != 3 || A[0].length != 3 || B.length != 3 || B[0].length!= 3) {
System.out.println("ERROR: Check your dimension! \n");
return new double[0][0];
}
double [] [] C = new double[3][3];
------------------------------------------------------
for (int i = 0; i < A.length; i++) {
for (int j = 0; j < B[0].length; j++) { Dieser Block darf verändert werden.
C[i][I][j] = 0;
for (int k = 0; k < A[0].length; k++) {
C[i][I][j] += A[i][I][k] * B[k][j];
return C;
}}}}
----------------------------------------------
public static void draw(double[][] M) {
for (int i = 0; i < M.length; i++)
for(int j = 0; j < M[0].length; j++)
System.out.print((j == 0 ? "|" : "") + M[I][j] + (j == M[0].length-1 ? "|\n" : "\t"));
System.out.println();
}
public static void main(String args[]) {
double [] [] A = {{ 0.0, -1.0, 0.0},
{ 1.0, 0.0, 0.0},
{ 0.0, 0.0, 1.0}};
double [] [] B = {{ 0.0, 1.0, 0.0},
{-1.0, 0.0, 0.0},
{ 0.0, 0.0, 1.0}};
double [] [] C = mult3x3(A, B);
draw(A);
System.out.println("*\n");
draw(B);
System.out.println("=\n");
draw(C);
}
}
Zuletzt bearbeitet von einem Moderator: