Alternate Method 2 :Write a program to find anagram or two words of same letter


Program
import java.util.*; public class arraysquare { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int f1=0,f2=0; String s1=sc.nextLine(); char c1[]=s1.toCharArray(); String s2=sc.nextLine(); char c2[]=s2.toCharArray(); for(int i=0;i<c1.length;i++) { f1=0; for(int j=0;j<c2.length;j++) { if(c1[i]==c2[j]) { f1=1; break; } } if(f1==0) { break; } } for(int i=0;i<c2.length;i++) { f2=0; for(int j=0;j<c1.length;j++) { if(c2[i]==c1[j]) { f2=1; break; } } if(f2==0) { break; } } if(f1==1 && f2==1) { System.out.println("Same Char"); } else{ System.out.println("Different char"); } } }
Input
Output

Similar Program