整数范围和其他一些问题

时间:2019-04-01 17:58:53

标签: java

我一直在为类编写一个有趣的编码项目,然后我尝试了一些if else语句和一些整数界限,一切都从那儿解脱了。请帮忙。我试图更改这些部分以确保边界有效,但它们却永远不会起作用,并且无论我使用什么数字,当我运行代码时,插入300磅60英寸或任何其他数字时,它总是显示重量不足。 / p>

System.out.println("Welcome to the BMI calculator portion!");
System.out.println("Lets begin!");
int bodyWeight;
System.out.println("Please enter your body wight in pounds here: ");
bodyWeight = input.nextInt();
int height;
System.out.println("Please enter your height here in inches: ");
height = input.nextInt();

//This part will convert pounds to kilograms
double kiloGram = bodyWeight / 2.205;

// This part will convert inches to cm
double centimeters = height * 2.54;

//This part will calculate the bmi using the BMI equation
double bmiResult = kiloGram / (centimeters * centimeters);

// This part will see the correlation of BMI to healthiness
if (bmiResult < 18.5) {
    y = "you are underweight according to your BMI.";
}
double bmiResults = 0;
if (bmiResults >= 18.5 && bmiResults <= 24.9) {
    y = "you are nomal weight according to your BMI.";
}
if (bmiResult >= 25 && bmiResults <= 29.5) {
    y = "you are overweight according to your BMI.";
}
if (bmiResults >= 30) {
    y = "you are obese according to you BMI.";
}
// this part will release the info about how the bmi worked
System.out.println("Congratulations, " + y);

//This part will give the user a summary of today's activity

System.out.println("Here is your result for today!");
System.out.println("You had " +breakfastCal+ " calories for breakfast today.");
System.out.println("You had " +lunchCal+ " calories for lunch today.");
System.out.println("You had " +dinnerCal+ " calories for dinner today.");
System.out.println("You had " +snackCal+ " calories for snack today.");
System.out.println("Your total caloric intake today was " +totalCal+ " calories, " +x);
System.out.println("For the BMI portion:");
System.out.println("You entered that you are " +bodyWeight+ " pounds, and " +height+ " inches.");
System.out.println(y);

1 个答案:

答案 0 :(得分:1)

根据评论中的所有陈述,我们可能有足够的理由提出答案。总结一下

  • 您有两个不匹配的变量
  • 您的bmi公式有误
  • 您没有详尽的if语句

固定代码:

[21318] Log opened at 2019-04-01 19:50:38
[21318] I: Connecting to configured address/port: 127.0.0.1:9000.
[21318] I: Connected to client. :-)
[21318] -> <init xmlns="urn:debugger_protocol_v1" 
    xmlns:xdebug="https://xdebug.org/dbgp/xdebug" 
    fileuri="file:///var/www/couchback/update.php" 
    language="PHP" 
    xdebug:language_version="7.0.33-0ubuntu0.16.04.2" 
    protocol_version="1.0" 
    appid="21318" 
    idekey="netbeans-xdebug">
        <engine version="2.7.0"><![CDATA[Xdebug]]></engine>
        <author><![CDATA[Derick Rethans]]></author>
        <url><![CDATA[https://xdebug.org]]></url>
        <copyright><![CDATA[Copyright (c) 2002-2019 by Derick Rethans]]></copyright>
    </init>
[21318]
[21318] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" status="stopping" re
ason="ok"></response>
[21318]
[21318] Log closed at 2019-04-01 19:50:40