I'm trying to write a simple program to identify if two phrases are anagrams of one another. I'm having trouble with sorting an array of characters and defining xarray and yarray.
public class Anagram1{
private String x;
private String y;
private char[] xarray; //?
private char[] yarray; //?
public Anagram1(String phrase1, String phrase2){
x = phrase1;
y = phrase2;
}
public void xlettersort(){
x= x.toLowerCase();
xarray = x.toCharArray();
xarray.sort();
}
public void ylettersort(){
y= y.toLowerCase();
yarray = y.toCharArray(); //?
yarray.sort(); //?
}
public void testAnagram(){
xlettersort();
ylettersort();
if(xarray == yarray){
System.out.println("Yes the two phrases is an anagram");
}
else{
System.out.println("No there is no anagram!");
}
}
}