public class MyDemo039 {
public static void main(String [] args) {
int [] arr = {8,4,2,1,23,344,12};
for ( int row=0; row<arr.length-1 ; row++) {
for ( int col=0; col < arr.length-1-row ; col++) {
if ( arr[col] < arr[col+1] ) {
int temp = arr[col];
arr[col]=arr[col+1];
arr[col+1]=temp;
}
}
}
for (int i=0; i<arr.length;i++) {
System.out.print(arr[i]+"-----");
}
}
}
Java冒泡排序法
最新推荐文章于 2024-07-18 20:13:39 发布