Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k 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 Reply

0 votes
by (71.8m points)

You didn't use the square. Should be

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...