Question: Help Fix Java Two Dimensional Array Error. The code is supose to get a two dimensional array of 9x9 ints, have a verification that it

Help Fix Java Two Dimensional Array Error.

The code is supose to get a two dimensional array of 9x9 ints, have a verification that it is a solution for a Sudoku puzzle, must return TRUE, and print out a line saying "It works!"

public class array { static int[][] grid = { {4, 2, 6, 5, 7, 1, 3, 9, 8}, {8, 5, 7, 2, 9, 3, 1, 4, 6}, {1, 3, 9, 4, 6, 8, 2, 7, 5}, {9, 7, 1, 3, 8, 5, 6, 2, 4}, {5, 4, 3, 7, 2, 6, 8, 1, 9}, {6, 8, 2, 1, 4, 9, 7, 5, 3}, {7, 9, 4, 6, 3, 2, 5, 8, 1}, {2, 6, 5, 8, 1, 4, 9, 3, 7}, {3, 1, 8, 9, 5, 7, 4, 6, 2} }; private boolean checkSudokuStatus(int[][] grid) { for (int i = 0; i < 9; i++) {

int[] row = new int[9]; int[] square = new int[9]; int[] column = grid[i].clone();

for (int j = 0; j < 9; j ++) { row[j] = grid[j][i]; square[j] = grid[(i / 3) * 3 + j / 3][i * 3 % 9 + j % 3]; } if (!(validate(column) && validate(row) && validate(square))) return false; } return true; for(return true) { System.out.println("Matrix works!"); } if(return false) { System.out.println("Matrix doesnt work"); }

}

private boolean validate(int[] check) { int i = 0; for (int number : check) { if (number != ++i) return false; } return true; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!