Java Median getMedian(int[] array)

Here you can find the source of getMedian(int[] array)

Description

get Median

License

Open Source License

Declaration

public static float getMedian(int[] array) 

Method Source Code

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

import java.util.*;

public class Main {
    public static float getMedian(int[] array) {
        // return median value

        if (array.length == 0)
            return 0;
        Arrays.sort(array);//from   ww  w .  j  a va 2s .com
        float median;
        if (array.length % 2 == 0)
            median = ((float) array[array.length / 2] + (float) array[array.length / 2 - 1]) / 2;
        else
            median = (float) array[array.length / 2];
        return median;
    }
}

Related

  1. calcMedian(final double[] values)
  2. calculateMedianOfArrayListInteger(List integerList)
  3. getMedian(double array[])
  4. getMedian(double[] a)
  5. getmedian(double[] vals, int nvalindex)
  6. getMedianValue(ArrayList values)
  7. median(ArrayList v)
  8. median(ArrayList values)
  9. Median(ArrayList values)