public List
{
char delimiter = ' ';
StringTokenizer tokenizer = new StringTokenizer(line, delimiter );
if ( tokenizer == null )
return null;
List
while ( tokenizer.hasMoreTokens() )
result.add(tokenizer.nextToken());
return result;
}
{
int charCount = 0;
if ( str == null || str.trim().isEmpty() )
return charCount;
int length = str.length();
for ( int i = 0; i < length; i++ )
{
if ( str.charAt(i) != ' ' )
charCount++;
}
return charCount;
}
System.out.println("Number of characters in '" + word + "' = " + countCharacters(word));
No comments:
Post a Comment