标签:des style http color io os java ar for
1 2 3 5 4 6 8 9 10 7
1 2 3 4 5 6 7 8 9 10 1 2 3 5 4 6 10 7 8 9
Arrays类提供的排序只能升序排,而且是对单调的数字或字母,但可以通过Comparator比较器来修改进行类排序,我想了一下也许这样可以实现对单一数字数组的降序排序?待会试一下
import java.io.*; import java.util.*; import java.math.*; import java.text.*; class node { public int tag,num; } class cmp implements Comparator<node> { public int compare(node A,node B) { return A.num-B.num; } } public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); node[] a=new node[11]; for(int i=0;i<10;i++){ a[i]=new node(); a[i].num=in.nextInt(); a[i].tag=i+1; } Arrays.sort(a,0,10,new cmp()); for(int i=0;i<10;i++) if(i!=9) System.out.print(a[i].num+" "); else System.out.print(a[i].num); System.out.println(""); for(int i=0;i<10;i++) if(i!=9) System.out.print(a[i].tag+" "); else System.out.print(a[i].tag); System.out.println(""); } }
标签:des style http color io os java ar for
原文地址:http://blog.csdn.net/qq_16255321/article/details/39323015