sweet_dreams吧 关注:37贴子:1,433
  • 1回复贴,共1

Java String Tokenizer

只看楼主收藏回复

import acm.program.*;
import java.util.*;
public class TokeniseString extends ConsoleProgram {
public void run() {
println("This program tokenises a string.");
String str = readLine("Please enter a string: ");
StringTokenizer tokeniser = new StringTokenizer(str, " ");
for (int i=0; tokeniser.hasMoreTokens(); i++) {
println(tokeniser.nextToken());
}
}
}


1楼2014-03-10 07:18回复
    StringTokenizer tokeniser = new StringTokenizer(str, " ");
    " " - use space as denominator
    ", " - use , or space as denominator
    ",. " - use, or . or space as denominator


    2楼2014-03-10 07:21
    回复