我如何计算这些以使我的 BMI 计算器工作?

How do I compute these to make my BMI Calculator work?

    String A;
    String B;
    Double num1, num2;

    System.out.print("Enter your weight in kg: ");
    A = br.readLine();
    num1 = Double.parseDouble(A);
    System.out.print("Enter your height in cm: ");
    B = br.readLine();
    num2 = Double.parseDouble(B);

    **double bmi = (100 * 100 * A) / (B * B);**
    System.out.println("" + bmi);

    if (bmi < 18.5) {
        System.out.println("You are underweight");
    } else if (bmi < 25) {
        System.out.println("You are normal");
    } else if (bmi < 30) {
        System.out.println("You are overweight");
    } else {
        System.out.println("You are obese");
    }
}

我认为问题出在这一行,我该如何计算它们才能正常工作? TIA! :双 bmi = (100 * 100 * A) / (B * B);

您将 AB 的解析值分别分配给 num1num2num1num2 现在包含解析后的值,而 AB 仍然保留其原始字符串值。要使这段代码起作用,您必须这样写:double bmi = (100 * 100 * num1) / (num2 * num2).