蓝桥杯——BASIC-13——数列排序
第二行包含n个整数,为待排序的数,每个整数的绝对值小于10000。
8 3 6 4 9
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int arrays[]=new int[n];
for (int i = 0; i < arrays.length; i++) {
arrays[i] = sc.nextInt();
}
for (int i1 = 0; i1 < arrays.length-1; i1++) {
for (int j = 0; j < arrays.length-1; j++) {
if(arrays[j]>arrays[j+1]) {
int change=arrays[j];
arrays[j]=arrays[j+1];
arrays[j+1]=change;
}
}
}
for (int j = 0; j < arrays.length; j++) {
System.out.print(arrays[j]+" ");
}
}
}
- 点赞
- 收藏
- 关注作者
评论(0)