import java.util.Arrays;
import java.util.Scanner;
public class Test6 {
public static void main(String[] args) {
// 6,使用冒泡排序法,对录入的10个整数按由小到大的顺序排序。
int[] ns = new int[10];
Scanner scan = new Scanner(System.in);
for(int i = 0;i < ns.length;i++) {
System.out.print("请输入第"+(i+1)+"个数:");
ns[i] = scan.nextInt();
}
for(int i = 0;i < ns.length;i++) {
for(int j = 0;j < ns.length-i-1;j++) {
if(ns[j] > ns[j + 1]) {
int temp = ns[j];
ns[j] = ns[j + 1];
ns[j + 1] = temp;
}
}
}System.out.println(Arrays.toString(ns));
}
}
08-11
2022
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-02
7135
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-19
901
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交