/** * This program uses a set to print all unique words in System.in */ public static void main(String[] args) { Set<String> words=new HashSet<String>(); long totaltime=0;
Scanner in=new Scanner(System.in);
while(in.hasNext()) { String word=in.next(); long callTime=System.currentTimeMillis(); words.add(word); //add all the words in set callTime=System.currentTimeMillis()-callTime; totaltime+=callTime;
/** * This program uses a set to print all unique words in System.in */ public static void main(String[] args) { Set<String> words=new HashSet<String>(); long totaltime=0;
Scanner in=new Scanner(System.in);
// while(in.hasNext()) // { // String word=in.next(); // long callTime=System.currentTimeMillis(); // words.add(word); //add all the words in set // callTime=System.currentTimeMillis()-callTime; // totaltime+=callTime; // // } while(true) { System.out.println("请输入单词"); String word=in.next(); if(word.equals("quit")) //当用户输入quit 单词时退出Scanner { System.out.println("退出"); break; } words.add(word); }