class MaoPaoDemo{
public static void main(String[]args){
int [] arr = {12,56,34,87,23,45};
maoPao(arr);
bianLi(arr);
}
public static void maoPao(int [] arr){
for(int x = 0;x<arr.length-1;x++){
for (int y = 0 ;y<arr.length-1-x;y++){
if (arr[y]>arr[y+1]){
int tem = arr[y];
arr[y]= arr[y+1];
arr[y+1]=tem;
}
}
}
}
public static void bianLi(int [] arr){
for (int x=0;x<arr.length;x++){
System.out.println(arr[x]);
}
}
} |
|