Advertisement
ggadget6

AP CS A 2018 FRQ #4

May 17th, 2018
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. public static int[] getColumn(int[][] arr2D, int c)
  2. {
  3. int[] result = new int[arr2D.length];
  4. for(int i = 0; i < arr2D.length; i++)
  5. {
  6. result[i] = arr2D[i][c];
  7. }
  8. return result;
  9. }
  10.  
  11. public static boolean isLatin(int[][] square)
  12. {
  13. boolean firstRow = false;
  14. boolean eachRow = true;
  15. boolean eachColumn = true;
  16.  
  17. firstRow = !(containsDuplicates(square[0]));
  18.  
  19. int counter = 0;
  20. while(eachRow && counter < square[0].length)
  21. {
  22. if(!(hasAllValues(square[0], square[i])))
  23. {
  24. eachRow = false;
  25. }
  26. counter++;
  27. }
  28. counter = 0;
  29.  
  30. while(eachColumn && counter < getColumn(square, 0))
  31. {
  32. if(!(hasAllValues(square[0], getColumn(square, i))))
  33. {
  34. eachColumn = false;
  35. }
  36. }
  37.  
  38. return firstRow && eachRow && eachColumn;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement