System.out.print("Your BMR is:");//BMR Calculation
        if (gender == ('M')){
            System.out.println(665+(6.23 * weight)+(12.7 * height)-(6.8 * age));

        } else if (gender == ('F')) {
            System.out.println(655+(4.35 * weight)+(4.7 * height)-(4.7 * age));

        };


我可以从上面的if循环中获取结果以生成BMR。但是,我似乎无法将BMR结果输入到底部的if循环中来进行运动计算。

System.out.println("What is your exercise routine, on the scale of 0 to 4? 0 is lowest and 4 is highest ");//Exercise Calculation
        int exercise = sc.nextInt();
        if (exercise == 0) {
            System.out.println(BMR * 1.2);
        } else if (exercise == 1) {
            System.out.println(BMR * 1.375);
        } else if (exercise == 2) {
            System.out.println(BMR * 1.55);
        } else if (exercise == 3) {
            System.out.println(BMR * 1.725);
        }else if (exercise == 4) {
            System.out.println(BMR * 1.9);
        };

最佳答案

您应该将BMR的值存储到局部变量中,以便以后可以在代码中访问它。

这是一个例子:

System.out.print("Your BMR is:");//BMR Calculation
double BMR = 0;
if (gender == ('M')){
    BMR = 665+(6.23 * weight)+(12.7 * height)-(6.8 * age);
    System.out.println(BMR);

} else if (gender == ('F')) {
    BMR = 655+(4.35 * weight)+(4.7 * height)-(4.7 * age);
    System.out.println(BMR);

};


然后,您可以稍后使用该BMR双变量。

07-26 01:51