资源简介
SSD3 全部练习和答案(原创)
值得参考 2009年12月做的,当时都能运行!
代码片段和文件信息
/*!Begin Snippet:file*/
import java.util.*;
public class CountTokensDemo {
public static void main(String[] args) {
String line = “this isatest“;
StringTokenizer st = new StringTokenizer(line “ “); // the second para is a string.
//String str = null; // this is a null string will print null
String str = ““; // this is a empty string
//String str; // this will not compile
int count = 0;
while (st.countTokens() !=0 ) { // counTokens() decrease the count
//each time nextTokens() is called
str = str + st.nextToken(); // programm will hange if we
//comment out this line.
count++;
}
System.out.println(str + “ “ + count);
}
}
/*!End Snippet:file*/
评论
共有 条评论