Write a program to find anagram or two words of same letter


Program
import java.util.Arrays; import java.util.Scanner; public class minmax { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("Enter sentence 1"); String s1=sc.next(); s1=s1.toLowerCase(); System.out.println("Enter sentence 2"); String s2=sc.next(); s2=s2.toLowerCase(); if(s1.length()!=s2.length()) { System.out.println("Invalid"); } if(s1.matches("^[a-zA-Z]*")){ char c1[] = s1.toLowerCase().toCharArray(); char c2[] = s2.toLowerCase().toCharArray(); Arrays.sort(c1); Arrays.sort(c2); if (Arrays.equals(c1, c2)) { System.out.println(s1 + " and " + s2 + " contain the same characters"); } else { System.out.println(s1 + " and " + s2 + " contain the different characters"); } } else { System.out.println("Invalid"); } } }
Input
Output