牛客网编程之java输入输出的坑
```
import java.util.;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
Set set = new TreeSet();
for (int i = 0; i < n; i++) {
set.add(sc.nextInt());
}
/*Iterator iterator = set.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next());
}/
for(int iter:set){
System.out.println(iter);
}
}
}
}
为什么上面可以通过,下面这样没法通过?
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Set set = new TreeSet();
while(sc.hasNext()){
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
set.add(sc.nextInt());
}
}
for(int iter:set){
System.out.println(iter);
}
}
}