日期:2014-05-20 浏览次数:20698 次
public class Hello { public static void main(String[] args) { int a[] = {1, 3, 2, 6, 4}; Arrays.sort(a, Collections.reverseOrder()); for (int i=0; i<a.length; ++i) System.out.print(a[i] + " "); } }
import java.util.*; class DescType implements Comparator { public int compare(Object o1, Object o2) { Integer i = (Integer)o1; Integer j = (Integer)o2; return (i<j?1:(i==j?0:-1)); } } public class Hello { public static void main(String[] args) { Integer a[] = {1, 3, 2, 6, 4}; //Arrays.sort(a, Collections.reverseOrder());//a Arrays.sort(a, new DescType()); //b for (int i=0; i<a.length; ++i) System.out.print(a[i] + " "); } }