我正在嘗試通過添加久坐,有點主動,活躍和Very_Active來計算BMR。代碼將編譯但不會計算。這是第一次嘗試,所以任何建議都是有幫助的。我已經成功創建了沒有添加類別的BMR,但現在我無法獲得計算。我試圖得到公正的FemaleBMR先工作之前,我就MaleBMR還添加用附加的if語句計算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)
你問它在一個'boolean'值來讀取,但它看到了一些其他輸入。請張貼輸入。 – chrylis
我不知道我會在哪裏找到其他輸入。再次,我是新來的Java。 – user2805461
爲什麼垂直空白的荒謬數量? –