I'm trying to make a program that calculates the average of 4 values.
Code:
private void botao1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int n1 = Integer.parseInt(txt1.getText());
int n2 = Integer.parseInt(txt2.getText());
int n3 = Integer.parseInt(txt3.getText());
int n4 = Integer.parseInt(txt4.getText());
float notaf = (n1+n2+n3+n4)/4;
res.setText(Float.toString(notaf));
}
The problem is that when I have to use the result of the mean (notaf) it always comes as an integer (7.0, 8.0, 3.0) and does not come with the decimal numbers (7.5, 8.5, 3.5) where I went wrong?
Print the program:
(The average in this case should be 6.75)