在控制台输入十个整数,存储到List中,用Collections类进行排序,全了!
记得给分!
不明白再问吧,百度上都是这种问题的答案,先百度,在问
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
//int[] list = new int[10];
List<Integer> list = new ArrayList<Integer>();
Random random = new Random();
Scanner in = new Scanner(System.in);
for (int i = 0; i < 10; i++) {
list.add(in.nextInt());
}
Collections.sort(list, Collections.reverseOrder());
System.out.println("您输入了"+list.size()+":");
for (Integer integer : list) {
System.out.println(integer.toString());
}
}
}