【说明】 以下程序实现数据的排序,将n个整数分别按照升序和降序进行排序,类SortInt_1实现升序排序,类SortInt_2实现降序排序。 【Java代码】 class SortInt_1{int i,i,k,temp;void SortInt(int a1,int a2[]){//升序排序 for(i=0;i<a1-1;i++){ k=i; for(j=i+1;j<a1;j++){if( (1) ) k=j;if(k !=i){ temp=a2[i];a2[i]=a2[k];a2[k]=temp;} } }} } class SortInt_2 (2) { int i,j,k,temp; void SortInt(int a1, int a2[]){//降序排序 for(i=0; i<a1-1;i++){ k=i; for(j=i+1;j<a1;j++){ if( (3) )k=j; } if(k !=i){ temp=a2[i];a2[i]=a2[k];a2[k]=temp; } } } } public class test{ public static void main(String args[]){ int a[]={10,55,100,35,87,90,100,16}; SortInt_1 NewInt= (4) ; NewInt.SortInt(a.lenvh,a);//调用SortInt_1类的方法 System.out.println("升序排列的数据: "); for(int i=0;i<a.length;i++){System.out.print(a[i]+" "); } System.out.println(); NewInt=new SortInt_2();//创建类SortInt_2的对象 (5) ;//调用相应方法进行降序排序 System.out.println("降序排列的数据: "); for(int i=0;i<a.length;i++){System.out.print(a[i]+" "); } } }