从键盘接收-行字符串,字符串只包含英文字母和空格,统计其中的单词数量,重复的单词只计算一次。
例如输入: I Very Very Like java程序需要输出: 4 要求:使用循环和判断语句实现。
首先你要说明你要用的语言的(因为你数据有java,就算你是java吧)
其次,这个方法有很多,我的参考
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
String[] s = str.split(" ");
List<String> l = new ArrayList<String>();
for (String c : s) {
l.add(c);
}
List<String> ld = new ArrayList<String>(new LinkedHashSet<String>(l));
System.out.println(ld.size());
}
热门标签: