Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Sudoku {
- private int[][] board;
- // Constructor - Throws IllegalArgumentException if input matrix is not
- // Sudoku-formatted
- public Sudoku(int[][] board) {
- if (board.length == 9 && board[0].length == 9) {
- this.board = board;
- } else {
- throw new IllegalArgumentException("Input matrix is not Sudoku-formatted");
- }
- }
- // Returns value at row i column j, Throws IllegalArgumentException if index
- // is out of bounds
- public int getValue(int i, int j) {
- if (i < 9 && j < 9 && i >= 0 && j >= 0) {
- return board[i][j];
- } else {
- throw new IllegalArgumentException("Index out of bounds");
- }
- }
- // Sets value in matrix, Throws IllegalArgumentException if index
- // is out of bounds
- public void setValue(int i, int j, int value) {
- if (i < 9 && j < 9 && i >= 0 && j >= 0) {
- board[i][j] = value;
- } else {
- throw new IllegalArgumentException("Index out of bounds");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement