Number of words in a string Infinite Loop
<p>Can someone tell me what is wrong with this? I'm trying to get the program to return the number of words in the string. It is stuck in an infinite loop...</p>

<pre><code>int NumberNames(String wholename)

{    
    String testname=wholename;

    int numnames=0;

     int posBlank= testname.indexOf(' ');

     while(testname.length()&gt;0)
    {   
       testname = testname.trim();

       testname=testname.substring(posBlank+1,testname.length());

       numnames++;

       System.out.println(testname);
    }    

    return numnames;

}
</code></pre>
