import java.util.Arrays; public class Lint5 { /* * 第k大的元素 */ public static void main(String[] args) { int[] nums = new int[] {1,4,5,6,2}; System.out.println(kthLargestElement(2, nums)); } public static int kthLargestElement(int n, int[] nums) { n --; Arrays.sort(nums); return nums[nums.length-n-1]; } }