Java Median median(double[] data)

Here you can find the source of median(double[] data)

Description

Taken from https://stackoverflow.com/questions/7988486/how-do-you-calculate-the-variance-median-and-standard-deviation-in-c-or-java Mr.

License

Open Source License

Parameter

Parameter Description
data to get the median

Return

the median

Declaration

public static double median(double[] data) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;

public class Main {
    /**/*  w  w  w.j a v a  2  s. c  o  m*/
     * Taken from
     * https://stackoverflow.com/questions/7988486/how-do-you-calculate-the-variance-median-and-standard-deviation-in-c-or-java
     * Mr. White's answer
     * 
     * @param data
     *            to get the median
     * @return the median
     */
    public static double median(double[] data) {
        Arrays.sort(data);

        if (data.length % 2 == 0) {
            return (data[(data.length / 2) - 1] + data[data.length / 2]) / 2.0;
        }
        return data[data.length / 2];
    }
}

Related

  1. median(double[] a)
  2. median(double[] a)
  3. median(double[] arr)
  4. median(double[] array)
  5. median(double[] array)
  6. median(double[] data, int length)
  7. median(double[] input)
  8. median(double[] l)
  9. median(double[] unsorted)