我正在尝试添加 Sedentary、Somewhat_Active、Active 和 Very_Active 来计算 BMR。代码将编译但不会计算。这是第一次尝试,所以任何建议都是有帮助的。我已经成功创建了一个没有添加类别的 BMR,但现在我无法进行计算。在我还添加 MaleBMR 之前,我试图让女性 BMR 先工作
import java.util.Scanner;
public class BMR2
{
public static void main(String[] args)
{
Scanner kybd = new Scanner(System.in);
System.out.print("Enter Height: ");
double Height = kybd.nextDouble ();
System.out.print("Enter Weight: ");
Double Weight = kybd.nextDouble ();
System.out.print("Enter Age: ");
int Age = kybd.nextInt ();
double FemaleBMR = 655 + 4.3 * Weight + 4.7 * Height - 6.8 * Age;
double MaleBMR = 66 + (6.3 * Weight) + (12.9 * Height) - (6.8 * Age);
int choc = 230;
System.out.println("Are you Sedentary, Somewhat_Active, Active, or Very_Active?: ");
boolean Sedentary = kybd.nextBoolean ();
boolean Somewhat_Active = kybd.nextBoolean();
boolean Active = kybd.nextBoolean ();
boolean Very_Active = kybd.nextBoolean ();
if (Sedentary)
System.out.println("chocolate bars for female: "+ FemaleBMR*1.2/choc);
else if (Somewhat_Active)
System.out.println("chocolate bars for female: "+ FemaleBMR*1.3/choc);
else if (Active)
System.out.println("chocolate bars for female: "+FemaleBMR*1.4/choc);
else if (Very_Active)
System.out.println("chocolate bars for female: "+FemaleBMR*1.5/choc);
}
}
编译但不会计算产量
java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:840)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextBoolean(Scanner.java:1756)
at BMR2.main(BMR2.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)