public static int wrongNumber(int[][] m) {
for (int i=0;i<4;i++) {
if (m[i][3] != m[i][0] + m[i][1] + m[i][2] + m[i][3]) {
int badrow = i; //BADROW DEFINED
break;
}
}
for (int i=0;i<4;i++) {
if (m[3][i] != m[2][i] + m[3][1] + m[3][0]) {
int badcolumn = i; //BADCOLUMN DEFINED
break;
}
}
int correctValue = (m[badrow][3]-m[badrow][2]-m[badrow][1]-m[badrow][0]) + m[badrow][badcolumn]; //ERROR HERE
return correctValue;
}```
The code above is used to take a 2D array that is 'incorrect' as input and output an integer that can be used to correct the array.
https://edabit.com/challenge/fEtBbju4zCmYKFAwH It is for this code problem.
I am getting the following errors:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
badrow cannot be resolved to a variable
badcolumn cannot be resolved to a variable```
What mistake have I made here? I defined the variables badcolumn and badrow in the function. My IDE is highlighting the following line of code:
int correctValue = (m[badrow][3]-m[badrow][2]-m[badrow][1]-m[badrow][0]) + m[badrow][badcolumn];```