public static void main(String[] args){
int arr[]={3,4,54,3,2,65,7,34,76,34,67};
//外层循环代表轮数,内层循环代表次数
for (int j = 0; j < arr.length-1; j++) {
for (int i = 0; i < arr.length-1-j; i++) {
if(arr[i]>arr[i+1]){
int emo=arr[i];
arr[i]=arr[i+1];
arr[i+1]=emo;
}
}
System.out.print(arr[j]+"\t");
}
for(int i=0; i<arr.length;i++){
System.out.prinltn(arr[i])
}
}
java之冒泡排序
于 2023-11-26 11:23:39 首次发布