Help with the calculation of a variable.
Hi!
I just started learning java and got an assigment to create a program that calculates the BMI, and tells you one of the four options. The problem is that it always skips the first three options and gives the fourth every time.
Code:
import javax.swing.JOptionPane;
public class CharDemo2 {
public static void main(String[] args) {
int pikkus;
int kaal;
double indeks;
String tulemus;
pikkus = Integer.parseInt(JOptionPane.showInputDialog("Sisesta enda pikkus:"));
kaal = Integer.parseInt(JOptionPane.showInputDialog("Sisesta enda kaal:"));
indeks = kaal / (pikkus * pikkus);
if (indeks >= 19 && indeks <= 25) {
tulemus = "Te olete normaalkaalus.";
} else if (indeks >= 25 && indeks <= 40) {
tulemus = "Te olete ülekaaluline.";
} else if (indeks > 40) {
tulemus = "Teie tervis on ohus.";
} else {
tulemus = "Te olete anorektik.";
}
JOptionPane.showMessageDialog( null, "Tulemus: " + tulemus);
}
}
I believe the problem lies within the calculation of the variable "indeks", but I can't put my finger on it. Help is greatly appreciated.