提交 cbea02fb 编写于 作者: 邓某人的父亲's avatar 邓某人的父亲

Add new file

上级 20ee749b
import java.util.*;
/**
* This program uses a set to print all unique words in System.in.
*
* @author Cay Horstmann
* @version 1.10 2003-08-02
*/
public class SetTest {
public static void main(String[] args) {
Set<String> words = new HashSet<>(); // HashSet implements Set
long totalTime = 0;
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
String word = in.next();
long callTime = System.currentTimeMillis();
words.add(word);
callTime = System.currentTimeMillis() - callTime;
totalTime += callTime;
}
Iterator<String> iter = words.iterator();
for (int i = 1; i <= 20 && iter.hasNext(); i++)
System.out.println(iter.next());
System.out.println(". . .");
System.out.println(words.size() + " distinct words. " + totalTime + " milliseconds.");
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册