For this program I have it almost completely done. I just need to find out that if the two strings are not anagrams where or why is it not an anagram? ex: banana/sanana = missing b or missing s.
import java.util.*; public class lab3 { public static void main(String[] args) { lab3 run = new lab3(); Scanner type = new Scanner(System.in); String firstStatement; String secondStatement; boolean anagrams; for(int i = 0;i<1;i=0){ System.out.println("Please enter the first string -or type QUIT to quit-."); firstStatement = type.nextLine(); System.out.println("Please enter another string -or type QUIT to quit-."); secondStatement = type.nextLine(); if(firstStatement.matches("QUIT")) break; else if(secondStatement.matches("QUIT")) break; else{ anagrams = run.isAnagram(firstStatement,secondStatement); System.out.println("The two are statements being an anagram is: "+anagrams); } } } public boolean isAnagram(String s1, String s2){ char[] c1 = s1.toCharArray(); char[] c2 = s2.toCharArray(); Arrays.sort(c1); Arrays.sort(c2); s1 = String.copyValueOf(c1); s2 = String.copyValueOf(c2); s1 = s1.trim(); s2 = s2.trim(); if(s1.equals(s2)) return true; else return false; } }
If you can help me it would be much appreciated.