I'm trying to get the average of up to 25 numbers. Right now, I'm confused on how to parse a String into an array. Here is the code as it stands:
final int SIZE = 25;
gradeArray = new double[SIZE];
String s;
int numElem = 0;
double average = 0;
do {
s = (String) JOptionPane.showInputDialog("Enter Grade", "");
if (s == null || s == ("")) {
} else {
try {
grades = Double.parseDouble(s);
if (grades > SIZE)
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Your input must be numeric!",
"Bad Data!", 0);
}
}
} while (s != null || !s.equals(""));
The SIZE constant is for testing purposes.
Double.parseDouble (s), so you do have some knowledge is parsing. What's not working for you?Double.paraeDouble(s);line.whilecondtion to&&instead of||gradeArray[counter++] = grades... btw. your code is really of bad quality (s == (""),s != null || !s.equals(""), etc.)