解题思路:
注意事项:
额外一个sc.nextLine();来消耗换行符,否则出错。同时遍历的时候要用split的长度
参考代码:
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()){ int n = sc.nextInt(); sc.nextLine(); String s = sc.nextLine(); int[] a = new int[n]; String[] split = s.split(" "); for (int i = 0; i < split.length; i++) { a[i] = Integer.parseInt(split[i]); } Arrays.sort(a); System.out.println(a[n/2]); } } }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:1283 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:591 |
校门外的树 (C语言代码)浏览:694 |
WU-C语言程序设计教程(第三版)课后习题11.12 (C++代码)(想学链表的小伙伴可以看看)浏览:902 |
IP判断 (C语言代码)浏览:763 |
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:685 |
【计算球体积】 (C语言代码)浏览:1101 |
1113题解浏览:786 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:1068 |
1126题解浏览:585 |