Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 3 hours ago.
i'm trying to solve a simple exercise using multithreading in java and this number came out of nowhere and basically idk what to do.
The exercise is checking a sudoku, and the chunk of code that fails is the one that looks the square's integrity
Here's the code (fixed, it was a dumb mistake)
public Runnable squareChecker = () -> {
for (int a = 0; a < arr.length; a+=3){
for (int b = 0; b < arr[0].length; b+=3){
Stack<Integer> nums = new Stack<>();
for (int c = a; c < a+3 && c < arr.length; c++){
for (int d = b; d < b+3 && d < arr[0].length; d++){
System.out.println(String.format("%d, %d, %d, %d",a,b,c,d));
if (nums.contains(arr[c][d])){
valid = false;
break;
}
else{
nums.push(arr[c][d]);
}
}
}
}
}
};
And here's the console output i was getting
0, 0, 0, 0
0, 0, 0, 1
0, 0, 0, 2
0, 0, 1, 0
0, 0, 1, 1
0, 0, 1, 2
0, 0, 2, 0
0, 0, 2, 1
0, 0, 2, 2
3, 0, 3, 0
3, 0, 3, 1
3, 0, 3, 2
3, 0, 4, 0
3, 0, 4, 1
3, 0, 4, 2
3, 0, 5, 0
3, 0, 5, 1
3, 0, 5, 2
-2147483647, 0, -2147483647, 0
Exception in thread "Thread-2" java.lang.ArrayIndexOutOfBoundsException: Index -2147483647 out of bounds for length 9
at Sudoku.lambda$new$2(Sudoku.java:48)
at java.base/java.lang.Thread.run(Thread.java:834)
Please login or Register to submit your answer