storing next word of sentence in a string
I am doing code on anagrams in java. I have checked some codes which ask
user to enter two strings and compare them. what i have to do is check all
anagrams in a single sentence in sequence of occurrence. So i want to take
"next word" of sentence in string 2 after storing first in string 1 and
apply anagrams logic. i want know how to search for next word in user
entered string and store it in variable? please help me out asap. thanks
in advance!!
i have tried following code
public class anagram2 {
boolean check(String s1,String s2)
{
char a1[]= s1.toCharArray();
char a2[]= s2.toCharArray();
int []index1= new int[26];
int []index2= new int[26];
int i = 0;
for(i=0;i<a1.length;i++)
{
index1[a1[i]-'a']++;
}
for(i=0;i<a2.length;i++)
{
index2[a2[i]-'a']++;
}
for(i=0;i<26;i++)
{
if(index1[i]!=index2[i])
return false;
}
return true;
}
}
No comments:
Post a Comment