import java.util.Scanner;
public class ex1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[] a = new int[11]; //1.创建数组,初始值为0
for (int i = 0; i < 5; i++) {
int t = scanner.nextInt(); //2.循环输入5个数
a[t]++; //并进行计数
}
for (int i = 0; i < a.length; i++) { //3.判断a[0] ~ a[a.length - 1]
for (int j = 0; j < a[i]; j++) { //4.出现了几次就打印几次
System.out.print(i + " ");
}
}
System.out.println();
for (int i = a.length - 1; i > 0; i--) {
for (int j = 0; j < a[i]; j++) {
System.out.print(i + " ");
}
}
}
}
冒泡排序
基本思想
每次比较两个相邻的元素,如果它们的顺序错误就把它们交换过来
注:从大到小排序,越小的越靠后
核心:双重嵌套循环



