Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

my java bmi calculator giving the same answer

i'm trying to make a bmi calculator but the answer keeps being the same.

i tried putting numbers height=1.50 meter weight=100 kg but the answer was underweigth

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    double bmi = 0;
    double weightinkg = 0;
    double heightinmeter = 0;
    String status = "";
    System.out.println("Enter the weight in Kg :");
    weightinkg = sc.nextDouble();
    System.out.println("Enter the height in Meter : ");  //enter the age
    heightinmeter = sc.nextDouble();
    if ((weightinkg <= 0) && (heightinmeter <= 0))
        System.out.println("ERROR: Negative number");
    double square = Math.pow(heightinmeter, 2);
    bmi = weightinkg / heightinmeter;
    if (bmi >= 0) {
        if (bmi >= 0 && bmi <= 24) {
            status = "Under Weight";
        } else if (bmi >= 25 && bmi <= 29) {
            status = "Healthy";
        } else if (bmi >= 30 && bmi <= 34) {
            status = "Overweight";
        } else
            status = "Obese";
    }
    else
        System.out.println("Invalid BMI (number must be positive");
    System.out.printf("Hello, your status is %s ! Please come again!", status);
}
question from:https://stackoverflow.com/questions/65936771/my-java-bmi-calculator-giving-the-same-answer

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You didn't use the square. Should be

    double square = Math.pow(heightinmeter, 2);
    bmi = weightinkg / square;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...