title: What is the bug in my "find median" implementation?
body: <p>I found someone who had a similar problem (<a href="https://stackoverflow.com/questions/11955728/how-to-calculate-the-median-of-an-array">How to calculate the median of an array?</a>), but I couldn't figure out how to incororate it in to my own code since I am rather new to java. Right now, my findmedian method is returning 0 instead of the actual median and I can't seem to figure it out. Thanks!    </p>
  
  <pre><code>import java.util.Scanner;
  import java.util.Arrays;
  
  public class Original
  {
      public static void main(String[] args)
      {
          Scanner inputNumber = new Scanner(System.in);
          Scanner dataItem = new Scanner(System.in);
          Scanner input = new Scanner(System.in);
  
          System.out.print("This stores a list of contirbutions to a charity drive.\n ");
          System.out.print("How many contributors will be entered? ");
  
          double contributors = inputNumber.nextDouble();
          double contributions[ ] = new double[50];  
          double contributions_check[] = findData (contributors, contributions);
  
          System.out.print("See if the contributions are correct. ");
  
          // Displays the contributions, loop allows numbers to be displayed correctly
          for (int count = 0; count &lt; contributors; count++) {
              System.out.print(contributions_check[count] + "    ");
          }
  
          double median = findmedian(contributors,contributions_check);
          System.out.print("\n The median contribution is: " + median);
      }
  
      public static double[] findData(double n, double[] contributions2)
      {
          Scanner dataItem = new Scanner(System.in);
  
          // x must be 0 and x must be &lt; than n
          for (int x = 0; x &lt; n; x++) {
              System.out.print("Please enter the next contribution: ");
              contributions2[x] = dataItem.nextDouble();
          }
  
          return contributions2;
      }
  
      public static double findmedian(double n, double data[])
      {
          Arrays.sort(data);
          double median;
  
          if (data.length % 2 == 0) {
              median = ((double) data[data.length / 2] +
                        (double) data[data.length / 2 - 1]) / 2;
          } else {
              median = (double) data[data.length/2];
          }
  
          return median;
      }
  }
  </code></pre>