我目前正在尝试创建一个体重指数计算器,但我一直试图将一个人高度的英尺和英寸转换为一个以英寸为单位的值,因为我不知道如何捕获两个不同的值(英尺和英寸)然后验证它们。
公开课体重指数{
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;
}
最佳答案
这看起来不对 while (height < inches || height > inches)
事实上,整个heightInInches()
必须修改。您通过显示英尺和英寸来接受用户输入的方式是不正确的。
关于java - 使用方法,我无法让它读取两个不同的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13123727/