[java]代码库
public class Example {
int arry[]=new int[]{3,1,5,4,2,7,8,9,6};
public void play(){
System.out.println("arry原来数组元素是:");
for(int i=0;i<arry.length;i++){
System.out.print(" "+arry[i]);
}
arry=sort(arry);
System.out.println("\n排序后的arry数组元素:");
for(int arryIndex=0;arryIndex<arry.length;arryIndex++){
System.out.print(" "+arry[arryIndex]);
}
}
private int[] sort(int[] arry2) {
for(int i=1;i<arry.length;i++){
for(int j=0;j<arry.length-i;j++){
if(arry[j+1]<arry[j]){
int temp=arry[j];
arry[j]=arry[j+1];
arry[j+1]=temp;
}
}
}
return arry2;
}
}
public class Main {
public static void main(String args[]){
Example t=new Example();
t.play();
}
}
by: 发表于:2017-07-14 10:10:19 顶(0) | 踩(0) 回复
??
回复评论