class lianxi7
{冒泡排序法
public static void main(String[] args)
{
int [] arr ={78,54,65,24,56};
System.out.println("从小到大的顺序是");
maopao(arr);
System.out.println();
System.out.println("从大到小的顺序是");
maopao1(arr);
}
//从小到大
public static void maopao(int [] arr){
for(int i=0;i<arr.length-1;i++){
for(int j = 0;j<arr.length-1-i;j++){
if(arr[j]>arr[j+1]){
int temp = arr[j+1];
arr[j+1] = arr[j];
arr[j] = temp;
}
}
}
for(int i = 0;i<arr.length;i++){
System.out.print(arr[i]+" ");
}
}
//从大到小
public static void maopao1(int [] arr){
for(int i = 0;i<arr.length-1;i++){
for(int j = 0;j<arr.length-1-i;j++){
if(arr[j+1]>arr[j]){
int temp = arr[j+1];
arr[j+1] = arr[j];
arr[j] = temp;
}
}
}
for(int i = 0;i<arr.length;i++){
System.out.print(arr[i]+" ");
}
}
}