题解 | #争夺前五名#
争夺前五名
http://www.nowcoder.com/practice/cd052308a1c44a88ad00255f312c3e14
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
// 保存数据
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
// 冒泡排序 降序 小的往后放
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (arr[j] < arr[j + 1]) {
int tmp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = tmp;
}
}
}
// 输出前5个数
for (int i = 0; i < 5; i++) {
System.out.print(arr[i] + " ");
}
}
}