I have the following code:
package while2;
import javax.swing.JOptionPane;
public class While2 {
public static void main(String[] args) {
int numero;
int i=1;
int suma=0;
int TotalNumeros=3;
double promedio= 0;
while(i<=TotalNumeros) {
numero= Integer.parseInt(JOptionPane.showInputDialog ("Ingresa el numero"));
suma= numero+suma;
i=i+1;
}
promedio= suma/TotalNumeros;
JOptionPane.showMessageDialog(null,"El valor total de la suma es: " + suma);
JOptionPane.showMessageDialog(null, "El promedio es:" + promedio);
}
}
The problem is that the average does not calculate the decimals.
Example: if the answer is 8
the average gives me = 2.0
I did it in Excel and it gives me 2,666666667
.