如何用Java解决这个问题

从键盘输入一个人的体重(公斤)和身高(米),计算其BMI指数并输出体重状态,体重指标BMI(Body Mass Index)=体重/身高的平方(kg/m2)。BMI<18.5,偏瘦;18.5<=BMI<24,正常;24<=BMI<27,偏胖;27<=BMI<30,肥胖;BMI>=30,重度肥胖。

public class BMI {
    public static void main(String[] args) {
        double weight,tall;
        double BMI;
        Scanner input = new Scanner(System.in);
        System.out.print("体重(KG):");
        weight = input.nextDouble();
        System.out.print("身高(M):");
        tall = input.nextDouble();
        BMI = weight / (tall * tall);
        showBMI(BMI);
    }

    static void showBMI(double BMI) {
        if (BMI < 18.5) {
            System.out.print("身体质量指数BMI=" + BMI + " 偏瘦");
        } else if (BMI >= 18.5 && BMI < 24) {
            System.out.print("身体质量指数BMI=" + BMI + " 正常");
        } else if (BMI >= 24 && BMI < 27) {
            System.out.print("身体质量指数BMI=" + BMI + " 偏胖");
        } else if (BMI >= 27 && BMI < 30) {
            System.out.print("身体质量指数BMI=" + BMI + " 肥胖");
        } else if (BMI >= 30) {
            System.out.print("身体质量指数BMI=" + BMI + " 重度肥胖");
        }
    }
}

有帮助请点下采纳该答案,谢谢!