/**
* zuozhe:邵梦瑶
* 2021-3-31
* 冒泡排序
*/
public class yao3 {
public static void main(String[] args) {
int [] numbers =new int[]{1,5,3,8,4,9,7};
for (int i = 0; i < numbers.length-1; i++) {
for (int j = 0; j < numbers.length-1-i; j++) {
if (numbers[j]>numbers[j+1]){
int temp=numbers[j];
numbers[j]=numbers[j+1];
numbers[j+1]=temp;
}
}
}
System.out.println("从小到大的排序结果是");
for (int i=0;i<numbers.length;i++)
System.out.println(numbers[i]+" ");
}
}
java冒泡排序
最新推荐文章于 2022-12-27 20:58:55 发布