冒泡排序
2021-01-04 18:29
标签:class pre array builder pen 定义 lse dem build public class demo { } 冒泡排序 标签:class pre array builder pen 定义 lse dem build 原文地址:https://www.cnblogs.com/joker-dj/p/12983745.html
public static void main(String[] args) {
//定义一个数组
int[] arr = {12, 15, 10, 18, 11};
System.out.println("排序前" + ArrayToString(arr)); for (int i = 0; i arr[j+1]){
int temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
System.out.println("排序后" + ArrayToString(arr));
}
/*数组转String*/
public static String ArrayToString(int[] arr){
StringBuilder sb=new StringBuilder();
sb.append("[");
for (int i = 0; i
下一篇:Java图片验证码