Here you can find the source of median(float[] values)
Parameter | Description |
---|---|
values | of numbers to calculate median for. |
public static float median(float[] values)
//package com.java2s; /**/*w w w .j a v a 2s.c o m*/ * Copyright 5AM Solutions Inc, ESAC, ScenPro & SAIC * * Distributed under the OSI-approved BSD 3-Clause License. * See http://ncip.github.com/caintegrator/LICENSE.txt for details. */ import java.util.Arrays; public class Main { /** * Calculates the median for the list of numbers. * * @param values of numbers to calculate median for. * @return median value. */ public static float median(float[] values) { if (values.length == 1) { return values[0]; } Arrays.sort(values); int middle = values.length / 2; if (values.length % 2 == 1) { return values[middle]; } else { return (values[middle - 1] + values[middle]) / 2.0f; } } }