私は探してみましたがどこでも答えは見つかりませんでしたが、どこに問題があるのかわかりません。Java:条件がfalseでまだ実行中の場合
プログラムを実行すると、calc!=odd
の値がfalseであり、私もそれを確認するために、値のコンソールプリントを作った、と声明を実行して、メイン
にfalseを返した場合、右後、DID calc!=even
と別のサイズの行列を持つ同じもの
私は実際に何が問題なのかわからない、誰かが明らかにすることを願って、ありがとう。
public class snake {
public static void main(String[] args) {
int[][] matrix = new int[5][7];
putNumbers(matrix);
printMatrix(matrix);
System.out.println("the matrix is snake? " + isSnake(matrix, matrix.length));
}
private static Boolean isSnake(int[][] matrix, int length) {
length--;
int calc,
odd = -1,
even = 1;
for (int i = 0; i < (matrix[length].length - 2); i++) {
calc = matrix[length][i] - matrix[length][i + 1];
if (length % 2 == 0) {
System.out.println(calc != odd); //value is false - prints
if (calc != odd); //executes anyway even when false
{
return false;
}
}
else {
System.out.println(calc != even);
if (calc != even); {
return false;
}
}
}
if (length == 0) return true;
return isSnake(matrix, length - 1);
}
private static void putNumbers(int[][] matrix) {
int n = 1;
for (int i = 0; i < matrix.length; i++) {
if (i % 2 == 0) {
for (int j = 0; j < matrix[i].length; j++, n++) {
matrix[i][j] = n;
}
} else {
for (int j = matrix[i].length - 1; j >= 0; j--, n++) {
matrix[i][j] = n;
}
}
}
}
private static void printMatrix(int[][] matrix) {
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++)
System.out.printf("%d\t", matrix[i][j]);
System.out.println();
}
System.out.println();
}
}
使用FindBugsのプラグインを削除し、余分なセミコロンがあります。 –
うわー、私は今でもそれを聞いてもダムを感じる、ありがとう –
@エデン・デュポン私は長いこと前に私に起こった同じようにそれを見つけるのが速かった。 anaswerを受け入れてください。 – Rahul