Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int n = 0;
- System.out.println("Enter number n:");
- n = input.nextInt();
- char[][] ls = new char[n][n];
- String tempString = "";
- for(int i = 0 ; i < n ; i++)
- {
- for(int j = 0 ; j < n ; j++)
- {
- System.out.println("Enter the letter for " + i + "," + j);
- tempString = input.nextLine();
- if(tempString.length() > 1)
- {
- System.out.println("Invalid input");
- }
- else
- {
- ls[i][j] = tempString.charAt(0);
- }
- }
- }
- boolean latinSquare = true;
- for(int i = 0 ; i < n && latinSquare ; i++)
- {
- for(int j = 0 ; j < n && latinSquare ; j++)
- {
- char element = ls[i][j];
- for(int k = j + 1 ; k < n && latinSquare ; k++)
- {
- if(ls[i][j] == element)
- {
- latinSquare = false;
- }
- }
- for(int k = i + 1 ; k < n && latinSquare ; k++)
- {
- if(ls[i][j] == element)
- {
- latinSquare = false;
- }
- }
- }
- }
- if(latinSquare)
- {
- System.out.println("The square is a latin square");
- }
- else
- {
- System.out.println("The square is not a latin square");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement