I'm doing an algorithm in Java using BlueJ as an IDE. I use trackback algorithm to solve the problem and everything works perfectly except for the checkstyle. The checkstyle errors are:
Assignment of parameter i is not allowed [on line 336]
Assignment of parameter j is not allowed [on line 337]
However, as trackback requires the variables to be passed as the arguments and also be edited according to the situation, so I can't do anything about this.
Does anybody know how to fix this? This is my code (error lines are commented):
public boolean solve(int i, int j) {
if (i == 9) {
i = 0; // line 336
if (++j == 9) { // line 337
return true;
}
}
...
for (int value = 1; value <= 9; ++value) {
if (possible[value]) {
setCell(i,j,value);
if (solve(i+1,j)) {
return true;
}
}
}
game[i][j] = 0;
return false;
}
You get a warning because Checkstyle considers that modiying method arguments is a bad practice. Either ignore it (or change the checkstyle config) if you don't consider it as bad practice, or change the code to work on copies of the arguments:
public boolean solve(int iIndex, int jIndex) {
int i = iIndex;
int j = jIndex;
// same code as before
}