anyone enlighten me? i have to find the median...below i found the mean and read the question wrong. how do calculate the median? i have my text input file which has 7 ints, 1-7, so i kno #3 will show up for median...but i dont know how to code it...pls help!

import java.util.*;

class median{

    public static void main(String[] args) throws Exception{
    ArrayList<Integer> store = new ArrayList<Integer>();
    String filename;
    System.out.println("Please type in the name of the file");
    Scanner readerUsr = new Scanner(;
    filename = readerUsr.nextLine();
    File inputFile = new File("int.txt");

    Scanner reader = new Scanner(inputFile);




    static void calculateSum(ArrayList<Integer> myArray){

    Iterator<Integer> iterator = myArray.iterator();
     int sum=0;
     int n=0;

     sum +=;

    double getAverage = sum/n;
    System.out.println("The Average is " + getAverage + "");


Could you please post your input text file?

Also I believe you can use the method get() from the ArrayList to retrieve an object at a specific index, therefore I think you can use something like:

median = myArray.get(medianIndex);


You give no indication that you understand what you are trying to do. You should know that the median is defined as the central value in a set. If the set has an even number of elements it is the arithmetic mean of the central two. If you order the values in the array it can be found by taking the central index. (3 in the example). The task then becomes, sort the array and determine the central value(s).

This article has been dead for over six months. Start a new discussion instead.