我目前正在嘗試創建一個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;
}
我知道這一點是錯誤的,因爲我需要驗證身高,但這樣做,我不能分開腳或英寸? –
你的意思是不能分開腳或英寸?首先,你沒有一個明確的下限或上限爲英尺或英寸......要求用戶輸入一個值之間的值? – agirish
我剛剛糾正,因爲我一直在玩,並把它回到它是如何它是 –