日期:2014-05-20 浏览次数:20771 次
import java.util.*;
public class Test
{
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 s = in.next();
long callTime = System.currentTimeMills();
words.add(s);
callTime = System.currentTimeMills() - callTime;
totalTime = totalTime + callTime;
}
Iterator<String> it = words.iterator();
for(int i=1; i<=20 && it.hasNext(); i++)
{
System.out.println(it.next());
}
}
}
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;
public class Test {
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 s = in.next();
long callTime = System.currentTimeMillis();
words.add(s);
callTime = System.currentTimeMillis() - callTime;
totalTime = totalTime + callTime;
if(s.equals("exit")){ // 加个判断条件
break;
}
}
Iterator<String> it = words.iterator();
for (int i = 1; i <= 20 && it.hasNext(); i++) {
System.out.println(it.next());
}
}
}