# Average and standard deviation methods returning as NaN

I'm making a program that gets the averages and standard deviation of the numbers that are imputed in an array. I'm stuck on only one thing though: whenever the average and standard deviation are returned, it shows up as Not a Number. What is wrong with the code?

Here's the methods:

```    public mainFrame() {
initComponents();
}

private double avg;
private double stdDeviation;

/**
*
* @param numElem
* @return
*/
public double getAverage (double[] gradeArray, int numElem) {
double sum = 0;

for(int i=0;i<numElem;i++){
}
return (sum/numElem);
}

public double getStdDev (double[] gradeArray, int numElem, double avg){
double sum = 0;

for(int i = 0;i<numElem;i++){
}
return Math.sqrt(sum/numElem);
```

And here is the event code when the "Enter Grades" button is clicked on:

```final int SIZE = 25;
String s;
int numElem = 0;
double average = 0;

for(int i=0;i<=SIZE;i++){

if (s == null || s == ("")){
break;

}
else{
try{
txtMean.setText(average +"");
txtStdDev.setText(stdDeviation+"");

}
catch (NumberFormatException e){
}
catch (ArrayIndexOutOfBoundsException e){
JOptionPane.showMessageDialog (null, "You can only input 25 values!","Too much data!",0);
}

}
}
```

The problem is with division with such statement: return (sum/numElem); where numElm is initialized as0 and sum is also 0 because the following never gets executed:

```for(int i=0;i<numElem;i++){ //<---- numElem = 0
}
```

A NaN value is used to represent the result of certain invalid operations such as dividing zero by zero. NaN constants of both float and double type are predefined as Float.NaN and Double.NaN.

So initialize or set this numElem to some other value.