我是編碼的初學者。我正在創建一個BMI計算器,我應該使用2個參數:以千克爲單位的重量和以米爲單位的高度。使用Math.pow來平方高度。並返回一個雙值來計算BMI。用於Java的BMI計算器的參數
這是我到目前爲止。我知道這一切都搞砸了。幫助和建議表示讚賞。
{
public static void displayWeight (double pounds)//pounds to kilograms
{
double weight = (pounds * 2.2);
}
public static void displayHeight (double inches)//inches to meters
{
double height = inches * 0.0264;
}
public static void main (String[] args)
{
//greeting
System.out.print("I will calculate your BMI and how many calories you "
+ "need to burn per day to maintain a healthy weight.\n\n");
System.out.println("Please enter your weight in pounds: ");
Scanner keyboard = new Scanner(System.in);
double weight =keyboard.nextDouble();
System.out.println("Please enter your height in inches: ");
double height =keyboard.nextDouble();
System.out.println("Please enter your age in years: ");
double age =keyboard.nextDouble();
double bmi = weight/Math.pow(height, 2);
System.out.print("Your Body Mass Index is:" + bmi);
}
};
如果輸入的公斤重量和高度以米爲單位,您會得到正確的結果。 – Henry
*「我知道它全部搞砸了」*>擴展。你的代碼有什麼問題?只是說它不起作用是不夠的。 –