im trying to make a program thats supposed to check whether 2 strings are anagrams of each other (anagram = same letters in both strings, but in different orders... "cool as wet art" , and "cs at waterloo" for example).
[CODE=java]while (str2.get_Lengt h() != 0) //<---- checks whether second string is "cleared"
{
//loop, from start of string (k = 0) to end of string (length2) for (k = 0; k <= length2; k = k + 1)
{
char1 = str1.charAt(0);
y = 0; resets y
char2 = str2.charAt(0);
if (char2 == char1) //checks if two are the same, if they are, makes y = point in string with char 2
{
y = str2.IndexOf(ch ar2);
}
if (y > -1) //checks if y is positive, if so, takes a substring of all other letters
str2 = (str2.substring (0, y)) + (str2.substring (y + 1));
}
} [/CODE]
can anyone figure out why it wont work???
[CODE=java]while (str2.get_Lengt h() != 0) //<---- checks whether second string is "cleared"
{
//loop, from start of string (k = 0) to end of string (length2) for (k = 0; k <= length2; k = k + 1)
{
char1 = str1.charAt(0);
y = 0; resets y
char2 = str2.charAt(0);
if (char2 == char1) //checks if two are the same, if they are, makes y = point in string with char 2
{
y = str2.IndexOf(ch ar2);
}
if (y > -1) //checks if y is positive, if so, takes a substring of all other letters
str2 = (str2.substring (0, y)) + (str2.substring (y + 1));
}
} [/CODE]
can anyone figure out why it wont work???
Comment