public class Word Amount {
public static void main(String[] args) {
List words List=new Array List();//用来存储不重复的单词的集合
Scanner input=new Scanner(System.in);
System.out.print l n(“请输入英文句子,句子中只有英文单词和空格:”);
String sentence=input.next Line();
String []words=sentence.split(" “);//分割字符串
for(String word:words){//遍历字符串数组
word=word.to Lower Case();//将单词转换成小写
//判断集合中是否已存有不区分大小写的相同字符串,同时判断字符串是否是空串
if(!words List.contains(word)&&!word.equals(”"))
words List.add(word);//将字符串存储到集合中
}
System.out.print l n(“此句子共出现”+words List.size()+“个单词。”);
}
}