日期:2014-05-20 浏览次数:20748 次
import java.io.*; import java.util.*; class Keyadd{ public static void main(String args[]) throws Exception { Set<Integer> numbers = new TreeSet<Integer>(); System.out.println("请输入整数,输入end结束输入:"); BufferedReader re = new BufferedReader(new InputStreamReader(System.in)); String s = ""; while (!(s = re.readLine()).equals("end")) { int num = new Integer(s); numbers.add(num); } System.out.println("您输入了:"+numbers.size()+"个数字!"); System.out.println(numbers); } }
------解决方案--------------------
恩,TreeSet就可以但是Set里不许有重复的元素,用的时候注意