Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. public static void main(String[] args) {
  2.  
  3. Scanner input = new Scanner(System.in);
  4.  
  5. int n = 0;
  6.  
  7. System.out.println("Enter number n:");
  8. n = input.nextInt();
  9.  
  10. char[][] ls = new char[n][n];
  11. String tempString = "";
  12.  
  13. for(int i = 0 ; i < n ; i++)
  14. {
  15. for(int j = 0 ; j < n ; j++)
  16. {
  17. System.out.println("Enter the letter for " + i + "," + j);
  18. tempString = input.nextLine();
  19. if(tempString.length() > 1)
  20. {
  21. System.out.println("Invalid input");
  22. }
  23. else
  24. {
  25. ls[i][j] = tempString.charAt(0);
  26. }
  27. }
  28. }
  29.  
  30. boolean latinSquare = true;
  31. for(int i = 0 ; i < n && latinSquare ; i++)
  32. {
  33. for(int j = 0 ; j < n && latinSquare ; j++)
  34. {
  35. char element = ls[i][j];
  36. for(int k = j + 1 ; k < n && latinSquare ; k++)
  37. {
  38. if(ls[i][j] == element)
  39. {
  40. latinSquare = false;
  41. }
  42. }
  43. for(int k = i + 1 ; k < n && latinSquare ; k++)
  44. {
  45. if(ls[i][j] == element)
  46. {
  47. latinSquare = false;
  48. }
  49. }
  50. }
  51. }
  52. if(latinSquare)
  53. {
  54. System.out.println("The square is a latin square");
  55. }
  56. else
  57. {
  58. System.out.println("The square is not a latin square");
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement