有人可以告诉我这有什么问题吗?我试图让程序返回字符串中的单词数。它陷入了无限循环......
int NumberNames(String wholename)
{
String testname=wholename;
int numnames=0;
int posBlank= testname.indexOf(' ');
while(testname.length()>0)
{
testname = testname.trim();
testname=testname.substring(posBlank+1,testname.length());
numnames++;
System.out.println(testname);
}
return numnames;
}