package com.itheima;
import java.util.Arrays;
public class Test26 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] arr = new int[]{2,4,5,6,8,7,3};
bubbleSort(arr);
System.out.println(Arrays.toString(arr));
}
public static void bubbleSort(int[] arr){
int temp = 0;
for(int i=arr.length-1;i>0;--i){
for(int j=0;j<i;++j){
if(arr[j]>arr[j+1]){
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
}
|
|