package Array;
/**
* @Description:
* @Author: 落幕
* @Date: 2022/8/1 15:10
*/
public class bubbleSort {
public static void main(String[] args) {
//冒泡排序 最大的放最后
int[] arr={25,64,36,80,13};
int temp=0;
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]) {
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
System.out.println("\n"+"第"+(i+1)+"轮");
for (int j = 0; j < arr.length; j++) {
System.out.print(arr[j] + "\t");
}
}
}
}
运行
第1轮
25 36 64 13 80
第2轮
25 36 13 64 80
第3轮
25 13 36 64 80
第4轮
13 25 36 64 80
Process finished with exit code 0