题解 | #争夺前五名#
争夺前五名
https://www.nowcoder.com/practice/cd052308a1c44a88ad00255f312c3e14
import java.util.Scanner; import java.util.Collections; import java.util.Arrays; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); Integer[] integers=new Integer[n]; for(int i=0;i<n;i++){ integers[i]=sc.nextInt(); } Arrays.sort(integers,Collections.reverseOrder());//用函数逆向排序,输出前五个即可 for(int i=0;i<5;i++){ System.out.print(integers[i]+" "); } } }