私はJavaクラスの2週目にインタラクティブデザインの学生です。メトリックを使ってJavaでBMIを計算する
Iは、以下の式を使用して、BMIの計算を作成する必要があります。
w
BMI = ___
(h/100) 2
Wは体重(キログラム)であり、hはセンチメートルで高さ:下記の式を使用してBMIを計算します。分母は2乗であることに注意してください。ここで
が私のコードです:
/**
* Calculates the Body Mass Index (BMI) for the user. The user must type in his
* or her height in centimeters and weight in kilograms, and the computer prints
* out the user's BMI.
*/
import java.util.Scanner; // import class
public class BMI {
public static void main(String[] args) {
int weight;
int height;
double bmi;
Scanner console; // create a variable to represent the console
console = new Scanner (System.in); // create the object with new
System.out.print("How much do you weigh (in kg)? "); // user prompt to provide weight
weight = console.nextInt(); // read from console
System.out.print("How tall are you (in cm)? "); // user prompt to provide height
height = console.nextInt(); // read value from console
bmi = (double) weight/(height/100*height/100); // calculates BMI
System.out.println("Your BMI is " + bmi); // displays user's BMI
}
}
プログラム1があること、それを呼び出すことができる場合は、実行されますが、私は計算が間違って書かれたと思います。
私は計算をいくつかの方法でフォーマットしました: bmi =(double)weight /(height/100 * height/100);体重に100、高さに200を使用すると、体重を除いた体重が返されます。私は以下を試しました:
bmi =(倍)重量/高さ/ 100 *高さ/ 100;
bmi =(double)weight /(height/100 * height/100);
bmi =(double)weight /(height/100)*(height/100);
bmi =(double)weight /((height/100)*(height/100)); (重量/高さ/ 100 *高さ/ 100); bmi =(倍数)(重量/高さ/ 100 *高さ/ 100); 0123。
BMI =(ダブル)(重量/(身長/ 100 *高さ/ 100);
BMI =(ダブル)(重量/(高さ/ 100)*(高さ/ 100);
bmi =(ダブル)(重さ)/((高さ/ 100)*(高さ/ 100));
BMI =(ダブル)(体重)/身長/ 100 *高さ/ 100;
IのいずれかのGE tは100%の時間の重みであるか、変数として100と200でのみ機能します。私は75と150を試して、それも体重を返します。私もあなたが100でINT height
を分割するとき、それはまだint型であるため、それは小数点以下を切り捨てPEMDAS
「bmi = weight /(height/100.0 * height/100.0);」 –