题目:对10个数进行排序
1 public class _028Compositor {
2
3 public static void main(String[] args) {
4 compositor();
5 }
6
7 private static void compositor() {
8 Scanner scanner = new Scanner(System.in);
9 int[] a = new int[10];
10 System.out.println("请输入10个整数,数与数之间用空格分开:");
11
12 // 遍历输入的十个数
13 for (int i = 0; i < 10; i++) {
14 a[i] = scanner.nextInt();
15 }
16
17 // 对输入的十个数进行简单排序
18 for (int i = 0; i < 10; i++) {
19 for (int j = i + 1; j < 10; j++) {
20 if (a[i] > a[j]) {
21 int temp = a[i];
22 a[i] = a[j];
23 a[j] = temp;
24 }
25 }
26 }
27
28 System.out.println("排序结果为:");
29 // 输出排序结果
30 for (int i = 0; i < 10; i++) {
31 System.out.print(a[i] + " ");
32 }
33 }
34
35 }
网友评论