private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
double grades;
grades= Double.parseDouble(comprogGrds .getText())+Double.parseDouble (dsGrds .getText())+ Double.parseDouble (cwGrds.getText())+ Double.parseDouble(multGrds.getText())/4;
if(grades>=90){
average.setText(Double.toString(grades));
}else if(grades>=78 && grades<=79){
average.setText(Double.toString(grades));
}else if(grades>=74 && grades <=75){
average.setText(Double.toString(grades));
}
}
您刚刚错过了一组括号。你现在只把最后的数除以4。请尝试以下命令。
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
double grades;
grades= (Double.parseDouble(comprogGrds .getText())+Double.parseDouble (dsGrds .getText())+ Double.parseDouble (cwGrds.getText())+ Double.parseDouble(multGrds.getText()))/4;
if(grades>=90){
average.setText(Double.toString(grades));
}else if(grades>=78 && grades<=79){
average.setText(Double.toString(grades));
}else if(grades>=74 && grades <=75){
average.setText(Double.toString(grades));
}
}
作为解释,如果你有double result = 3+6+9+2/4;
,你将最终得到3+6+9+(2/4)。要解决这个问题,一组括号就足够了。double result = (3+6+9+2)/4;