计算机科学热量计算器1


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双变量。

最新更新