私のコードはエラーを出しますが、それを修正する方法がわかりません:
public class Cenas {
public static void main(String[] args) {
//gera matrizes de tamanho aleatório com uns e zeros
int a = 2;//(int)(Math.random() *3) + 1;
int b = 2;//(int)(Math.random() *3) + 1;
int[][]matriz = new int [a][b];
do{
for (int i=0; i<a; i++) {
for (int j=0; j<b; j++) {
matriz[i][j] = (int) Math.round(Math.random());
System.out.print(matriz[i][j] + " ");
}
System.out.println("");
}
}while(matrizIdentidade(matriz)==true); //the error is in here!!! the ";"
public static boolean matrizIdentidade (int[][]m){
boolean diagonal = false;
if (m.length==m[0].length) //matriz.Testada[0] é o comprimento da matriz
for (int i = 0; i < m.length; i++)
for (int j = 0; j < m[0].length; j++)
if(i==j && m[i][j]==1)
if(i!=j && m[i][j]==0)
diagonal = true;
return diagonal;
}
}
ランダム行列を生成し、それらが単位行列であるかどうかを教えてくれます。テストのために、System.out.printとdimension 2x2を配置しました。エラーにより、ループが無限ループになります...
";" コメントされた行に、(Eclipseでは)赤の下線が引かれ、エラーが発生します。
私はあなたが私の質問を見逃していると謙虚に思います。私のメソッドのステートメントが正しいかどうかはわかりませんが(私はそれに取り組んでいます)、ここで私をもたらすのは「;」です。エラーが発生します:「構文エラー、「}」を挿入してMethodBodyを完了します」。それが私のひどくコーディングされたロジックによるものであるならば、私は謝罪しました。しかし、代わりに、do-whileループで構文エラーが発生していることを示していると思います。