笔试题2:

import java.util.StringTokenizer;
public class String1
{

public static void main(String[] args)
{

String str=new String("I love Java I am a software engineer 我 是 java 男! ");
StringTokenizer strTo=new StringTokenizer(str);
System.out.println("空格数:"+(strTo.countTokens()-1));
System.out.println("单词的个数: "+strTo.countTokens());
System.out.println("输出结果:");

while(strTo.hasMoreTokens())
{
System.out.print(strTo.nextToken()+" ");
}
}
}

你可能感兴趣的:(java)