System.out.println("Enter the number of values in the array"); inString = br.readLine(); numOfValues = Integer.parseInt(inString);
for(int i = 1; i <numOfValues; i++) { System.out.println("Please enter the number in the array"); inString = br.readLine(); xIntegers[i] = Integer.parseInt(inString);
average = 0.0; average = average + xIntegers[i]; average = average/numOfValues; System.out.println("The Average is" + "" + average); }
}
public void writeValues() { for(int i= 1; i<numOfValues; i++) { System.out.println("The values in the array are" + xIntegers[i]); } }
public int getNumOfValues() { return numOfValues; }
public double getAverage() { return average; }
public double calStandardDev(int [] xIntegers, double average) { double sd = 0.0; double diff; double sum = 0.0; for (int i = 1; i < xIntegers.length; ++i) { diff = xIntegers[i] - average; sd = sum + diff * diff; } sd = Math.sqrt(sd/(xIntegers.length)); System.out.println("The Standard Deviation is" + "" + sd); return sd; }
}
//unyime i import java.io.*; public class TestArray {
/**THE MAIN PROGRAM STARTS HERE, PROMPTS THE USER FOR INPUT AND ALLOWS THE USER TO SET THE SIZE OF THE ARRAY, CALLS THE APPROPRIATE METHODS TO DO THE COMPUTATIONS AND PRINTS THE RESULT **/
public static void main (String []args) throws IOException { Array ta = new Array(); ta.readValues(); ta.writeValues();
} }
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
In the constructor public Array() you are setting the array xIntegers = new int [0]//has no elements
you need to initialize it after you have obtained the size from the user something like this
System.out.println("Enter the number of values in the array"); inString = br.readLine(); numOfValues = Integer.parseInt(inString); xIntegers = new int [numOfValues];//<----------- for(int i = 0; i <numOfValues; i++)//<-----------changed i = 1; to i = 0 {
unyime inok
Greenhorn
Joined: Oct 13, 2004
Posts: 29
posted
0
Thanks a lot, i think that should help.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.