Averages/Median: Difference between revisions
Content deleted Content added
Underscore (talk | contribs) →{{header|Perl 6}}: Replaced with a briefer implementation in the style of the Perl 5 and Python. |
→{{header|Java}}: Remove size check and use nice little int division formula instead |
||
Line 351: | Line 351: | ||
public static double median(List<Double> list){ |
public static double median(List<Double> list){ |
||
Collections.sort(list); |
Collections.sort(list); |
||
return (list.get(list.size() / 2) + list.get((list.size() - 1) / 2)) / 2; |
|||
return (list.get(list.size() / 2) + list.get(list.size() / 2 - 1)) / 2; |
|||
} |
|||
return list.get((list.size()-1)/2); |
|||
}</lang> |
}</lang> |
||