【发布时间】:2014-04-25 01:50:36
【问题描述】:
我的程序正在根据用户的年龄、身高、体重和性别计算并打印用户的 BMR 值。
但是,在根据输入检查性别并直接跳转到 else 语句时,我的程序无法正常工作。 这是我目前的代码,我该如何解决?
import java.util.Scanner;
public class MaintainingWeight
{
public static void main(String[] args)
{
//Instance Variables
int age, weight, inches; //weight in pounds, height inches
double BMR;
String gender;
//Program Introduction Welcoming the user
Scanner keyboard = new Scanner(System.in);
System.out.println("Hello fellow user, this program will help determine \nyour BMR value and tell the amount of chocalate bars you will need");
System.out.println("in order to maintain your body weight.");
//Ask the User to input their age, weight and height
System.out.println("Please enter your age.");
age = keyboard.nextInt();
System.out.println("Next enter your weight in pounds");
weight = keyboard.nextInt();
System.out.println("Now enter your height by inches\n (Reminder: to find your height in inches mutiply your height by feet to 12.000. (feet * 12.000))");
inches = keyboard.nextInt();
//Tell the user their gender then print their BMR Value
System.out.println("Please enter your gender. Enter M as Men or W as women");
gender = keyboard.nextLine();
if (gender.equalsIgnoreCase("M"))
{
System.out.println("Your BMR value is: ");
}
else if (gender.equalsIgnoreCase("W"))
{
System.out.println("Your BMR Value is: ");
}
else
{
System.out.println();
}
}
//Print to the user the amount of chocolate bars they need to consume to maintain their weight
}
【问题讨论】:
-
这对我来说很好。究竟是什么问题?
-
你的问题是什么?
-
@user3189142 我认为他需要方程式
-
他会遇到一些问题,因为 BMR 是用公制计算的
-
@user3189142 可能不是。还有一些计算器使用美制单位。