我发现,将数组定义为int型和long型都可以满足题目要求,但是不知道为啥long型运行速度快一点 以下是100分代码
import java.util.Scanner; public class Main{ public static void main(String[] args){ int n; long max=0; long min=0; double mid=0; Scanner sc = new Scanner(System.in); n=sc.nextInt(); long[] nums = new long[n]; for(int i=0;i<nums.length;i++) { nums[i]=sc.nextLong(); } //max & min if(nums[0]>nums[n-1]) { max = nums[0]; min = nums[n-1]; }else{ max = nums[n-1]; min = nums[0]; } System.out.print(max+" "); //mid if(n%2==0) { mid = (nums[n/2]+nums[n/2-1])/2.0; if((nums[n/2]+nums[n/2-1])%2==1) { System.out.printf("%.1f ",mid); }else { System.out.print(Math.round(mid)+" "); } }else { mid = nums[n/2]; System.out.print(Math.round(mid)+" "); } System.out.print(min); } }