Re: Average grade program
Try this, now finding out what I have changed and why is your job :)
Code:
import javax.swing.JOptionPane;
public class Average{
public static void main(String[] args) {
String input, amount;
double data[];
int gradetotal1;
double sum = 0, average = 0;
System.out.println("\tAverage Program");
amount = JOptionPane.showInputDialog("Input Number of grades to enter");
gradetotal1 = Integer.parseInt(amount);
data = new double[gradetotal1];
for (int i = 0; i < data.length; i++) {
input = JOptionPane.showInputDialog("Enter grades");
data[i] = Double.parseDouble(input);
}
for (int i = 0; i < data.length; i++) {
sum += data[i];
average = sum / data.length;
}
JOptionPane.showMessageDialog(null, "The total is: " + sum
+ " The Average is: " + average, "Result",
JOptionPane.INFORMATION_MESSAGE);
}
}
Re: Average grade program
data[] = new double(gradetotal1);
;)
Re: Average grade program
Code:
data[] = new double(gradetotal1);
:confused: What is that supposed to do?
Re: Average grade program
Just corrected a mistake :D he said data[] = gradetotal1; which is a mistake.
Re: Average grade program
Quote:
Originally Posted by
cens
data[] = new double(gradetotal1);
;)
Quote:
Originally Posted by
cens
Just corrected a mistake :D he said data[] = gradetotal1; which is a mistake.
The correct code (which is in javinpaul's last post) is
Code:
double data[];
...
data = new double[gradetotal1];
You don't need the [] in the assignment, just in the declaration.