程序:
package cn.sg.up;
/**
* 冒泡排序
*
*/
public class Demo04 {
public static void main(String[] args) {
int[] arr = new int[]{60,80,65,18,95,30,27,-10,-34,55};
//冒泡排序
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];
arr[j] = arr[j+1];
arr[j+1]=temp;
}
}
}
for(int i=0;i<arr.length;i++){
System.out.println(arr[i]);
}
}
}
程序截图:
看着程序发现规律,不解释了,容易看懂
Author:枫叶