统计字符串里面单词的个数
统计字符串里面单词的个数输入一长串的字符串,带空格那种,回车结束
输出字符串单词的个数 import java.util.Scanner;
public class StatisticalWord {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print(">>> ");
String string = scan.nextLine();
int count = string.split(" ").length;
System.out.println(count);
}
}
页:
[1]