Das Problem in calculateMainDiagonal Methode sein sollte, die Compiler-Fehler ich erhalte, ist:Kompilierungsfehler Schritte: int [] [] kann nicht Java in int umgewandelt werden
int[][] cannot be converted to int int sumD1 = calculateMainDiagonal(m);
Nun Haupt gleich bleiben sollte, wie es mein Professor ist Code. Jede Hilfe wird geschätzt. Ich glaube, ich werde einen int zurückgeben, aber ich bin mir nicht sicher. Ich
Versuche versucht:
public static int [][] calculateMainDiagonal(int sum);
public static int [][] calculateMainDiagonal(int [][] sum);
public static int calculateMainDiagonal(int sum)
Wenn ich dies einzugeben:
public static int calculateMainDiagonal(int [][] sum);
es gibt mir diese Compiler-Fehler statt:
java:50: error: missing method body, or declare abstract public static int calculateMainDiagonal(int [][] sum);
public class TesterProject
{
public static void main(String [] args)
{
int n = getMatrixSize();
int[][] m = makeAndFillMatrix(n);
printMatrix(m);
int sumD1 = calculateMainDiagonal(m);
System.out.println("The sum of the main diagonal is " + sumD1);
}
public static int getMatrixSize()
{
Scanner S = new Scanner(System.in);
System.out.println("give me a int to create the matrix");
int n = S.nextInt();
return n;
}
public static int [][] makeAndFillMatrix(int n)
{
Random generator = new Random(5);
int [][] r = new int[n][n];
int rand = generator.nextInt(10);
for(int i = 0; i < r.length; i++)
{
for(int j = 0; j < r[i].length; j++)
{
r[i][j]= rand;
}
}
return r;
}
public static void printMatrix(int [][] matrix)
{
for(int r = 0; r < matrix.length; r++)
{
for(int c = 0; c < matrix[r].length; c++)
{
System.out.print(matrix[r][c] + " ");
}
System.out.println();
}
}
//only problem is this method
public static int calculateMainDiagonal(int sum);
{
int total = 0;
for (int r = 0; r < total; r++)
{
total += r;
}
return total;
}
}
Die Linie, die in ihm 'calculateMainDiagonal' hat ein zusätzliches Semikolon erklärt. – ajb
Rufen Sie auch nicht den Parameter 'sum' auf. Sie berechnen einen Wert aus einer Matrix. Die Matrix ist der Parameter, nicht die Summe. – ajb
OMG, ich bin so dumm ... Ich habe stundenlang daran gearbeitet lol. Ich kann nicht glauben, dass ich das nicht bemerkt habe. – IDK