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.*;
import java.io.*;
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(System.in);
filename = readerUsr.nextLine();
File inputFile = new File("int.txt");
Scanner reader = new Scanner(inputFile);
while(reader.hasNext()){
store.add(Integer.parseInt(reader.nextLine()));
}
calculateSum(store);
}
static void calculateSum(ArrayList<Integer> myArray){
Iterator<Integer> iterator = myArray.iterator();
int sum=0;
int n=0;
while(iterator.hasNext()){
iterator.next();
sum += iterator.next();
n++;
}
double getAverage = sum/n;
System.out.println("The Average is " + getAverage + "");
}
}