我收到NaN錯誤,當我編譯這個時,我無法弄清楚我做錯了什麼?我試着移動變量來看看我能否讓它們工作,但沒有任何東西。請注意我放置的類型爲double的變量,用於英寸= keyboard.nextInt()後的bmi。我認爲它的零分錯誤,但我不知道我除以零。BodyMassIndex計算器錯誤(NaN)
import java.util.Scanner;
public class BodyMassIndex {
public static void main(String[] args) {
// TODO Auto-generated method stub
int pounds =0;
int feet = 0;
int inches = 0;
double heightMeters = ((feet * 12) + inches) * .0254;
double mass = pounds/2.2;
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter your weight in pounds");
pounds = keyboard.nextInt();
System.out.println("Enter how many feet you are");
feet = keyboard.nextInt();
System.out.println("Enter how many inches after feet");
inches = keyboard.nextInt();
double bmi = mass/(heightMeters * heightMeters);
System.out.println(mass);
System.out.println(bmi);
if(bmi < 18.5){
System.out.println("Underweight");
}
else if ((bmi >= 18.5) && (bmi < 25)){
System.out.println("Normal weight");
}
else if ((bmi >= 25) && (bmi < 30))
System.out.println("Above weight");
else
System.out.println("Obese");
}
}
請在此處詢問之前嘗試[鴨調試](http://www.rubberduckdebugging.com/)和其他基礎知識。要求我們調試你的程序是完成任何事情的可怕方法。 – jdv