how to compare each token of two strings
843810Feb 15 2002 — edited Feb 18 2002hi guys,
first of all, thank you guys helping me, whoever he is. the problems i had before have beed solved.....
now i got another new problem about below source code.
import java.util.*;
public class t1 {
public static void main(String[] args)
{
String s1,s2;
StringTokenizer str1=new StringTokenizer("i like you very much");
StringTokenizer str2=new StringTokenizer("i hate you much more");
s1=str1.nextToken();
s2=str2.nextToken();
while(str1.hasMoreTokens()&&str2.hasMoreTokens())
{
if (s1.equals(s2))
System.out.println("the same words:\n"str1.nextToken()+str2.nextToken());
else
System.out.println("the different words:\n"+str1.nextToken() +str2.nextToken());
}
}
the purpose here is to compareto each token of two strings...
so i hope that output is:
the same words:
i i
you you
the different words:
like hate
very much
much more
*****************
but actually the output of the code is below
C:\javatest\hw1>java t1
the same words:
likehate
the same words:
youyou
the same words:
verymuch
the same words:
muchmore
could anybody tell me where i made the mistakes...
thanks a lots............