public class Test {
public static void main(String[] args){
System.out.println("请输入:");
Scanner sc = new Scanner(System.in);
Set<Integer> set = new HashSet<Integer>();
while(true){
Integer i = sc.nextInt();
if(i == null){
continue;
}
if(i == 0){
break;
}
set.add(i);
}
System.out.println("您一个输入了" + set.size() + "个不重复的整数");
}
}
没有做异常处理,输入字符会报错~~~