Advertisement
Guest User

Untitled

a guest
Feb 16th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1.  
  2. public class Sudoku {
  3. private int[][] board;
  4.  
  5. // Constructor - Throws IllegalArgumentException if input matrix is not
  6. // Sudoku-formatted
  7. public Sudoku(int[][] board) {
  8. if (board.length == 9 && board[0].length == 9) {
  9. this.board = board;
  10. } else {
  11. throw new IllegalArgumentException("Input matrix is not Sudoku-formatted");
  12. }
  13. }
  14.  
  15. // Returns value at row i column j, Throws IllegalArgumentException if index
  16. // is out of bounds
  17. public int getValue(int i, int j) {
  18. if (i < 9 && j < 9 && i >= 0 && j >= 0) {
  19. return board[i][j];
  20. } else {
  21. throw new IllegalArgumentException("Index out of bounds");
  22. }
  23. }
  24.  
  25. // Sets value in matrix, Throws IllegalArgumentException if index
  26. // is out of bounds
  27. public void setValue(int i, int j, int value) {
  28. if (i < 9 && j < 9 && i >= 0 && j >= 0) {
  29. board[i][j] = value;
  30. } else {
  31. throw new IllegalArgumentException("Index out of bounds");
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement