Your setting of count = 0
should be immediately before the appropriate for
loop, not after it, and I would actually call that variable sum
(renaming your sum
to target
) since it's not really a "count" at all, e.g:
private boolean rowCheck(){
int target = size * (size + 1) / 2;
for (int i = 0; i <size; i++) {
int sum = 0; // declaration moved, too
for (int j = 0; j < size ; j++) {
sum += board[i][j];
}
if (sum != target) return false;
}
return true;
}
The point being that you should be setting the variable in advance of the loop, not resetting it afterwards (that being a pointless operation on the final iteration).
I would probably also move sumtarget
into a class member, calculated in the constructor.