我目前正在尝试创建一个 bmi 计算器,但由于我不知道如何捕捉两个不同的值(英尺和英寸)然后验证他们。
公共类 BMI {
public static void main (String[] args)
{
System.out.println("Value between 2 and 7: " + heightInInches(2,7));
System.out.println("Value between 0 and 11: " + heightInInches(0,11));
System.out.println("Value between 3 and 30: " + weightInPounds(3,30));
System.out.println("Value between 0 and 13: " + weightInPounds(0,13));
}
public static int heightInInches(int lower, int upper)
{
Scanner kybd = new Scanner(System.in);
System.out.printf("Enter your height between %d and %d: ", lower, upper);
int height = kybd.nextInt();
while (height < lower || height > upper)
{
System.out.printf("Retry between %d and %d:" , lower, upper);
height = kybd.nextInt();
}
return height;
}