标签:sort bsp spl 个人 parse oid ble 简单 ring
public class bubbleSort {
public static void main(String[] args) {
while(true){
System.out.println("请输入数组,以空格分割,以回车键结束");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
String[] strs = str.split(" ");
int[] arrs = new int[strs.length];
for (int i=0;i<strs.length;i++) {
arrs[i] = Integer.parseInt(strs[i]);
}
int temp = 0;
for (int i = 0; i < arrs.length-1; i++) {
for (int j = i+1; j < arrs.length; j++) {
if(arrs[j]>arrs[i]){
temp = arrs[i];
arrs[i] = arrs[j];
arrs[j] = temp;
}
}
}
System.out.println("从大到小排序:");
for (int i : arrs) {
System.err.print(i+" ");
}
System.out.println();
}
}
}
学习之余,写个简单的冒泡排序,纯属个人娱乐
标签:sort bsp spl 个人 parse oid ble 简单 ring
原文地址:https://www.cnblogs.com/syd-fish-cat/p/9152916.html