andy6804tw
8/2/2016 - 7:25 AM

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=30519 這題由於不知有多筆測資所以放到ArrayList

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=30519

這題由於不知有多筆測資所以放到ArrayList

import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		ArrayList<Integer> list=new ArrayList<Integer>();
		while(scn.hasNext()){
			list.add(scn.nextInt());
		}
		Collections.sort(list);
		if(list.size()%2==0)
			System.out.println(list.get(list.size()/2));
		else
			System.out.println(list.get((list.size()+1)/2));
	}
		/* 
    題目:2016 闖關組[Problem B3] The Median of a List of Numbers
    作者:1010
    時間:西元 2016 年 8 月 */
}