首页 > 试题广场 >

(医疗应用程序:BMI) 修改程序清单 34, 让用户输人

[问答题]
 (医疗应用程序:BMI) 修改程序清单 34, 让用户输人重ft、英尺和英寸。例如:一个人身高是 5 英尺 10 英寸,输入的英尺值就是 5、英寸值为 10。下面是一个运行示例:


public class Test {
	public static void main(String[] args){
		

		//程序说明:输入相应数据计算BMI并显示
		//提示用户输入
		Scanner input = new Scanner(System.in);
		
		System.out.print("Enter weight in pounds:");
		double pounds = input.nextDouble();
		System.out.print("Enter weight in feets:");
		double feets = input.nextDouble();
		System.out.print("Enter weight in inches:");
		double inches = input.nextDouble();
		  
			//单位转换
		final double KILOGRAMS_PER_POUND = 0.45359237;
		final double METERS_PER_INCH = 0.0254;
		double apounds = pounds * KILOGRAMS_PER_POUND;
		double afeet = (feets * 12 + inches) * METERS_PER_INCH;
		//计算BMI
		double bmi = apounds / Math.pow(afeet, 2);
		//显示结果
		System.out.println("BMI is " + bmi);
		if(bmi < 18.5)
			System.out.println("Thin");
		else if(bmi >= 18.5 && bmi < 25.0)
			System.out.println("Normal");
		else if(bmi >= 25.0 && bmi < 30.0)
			System.out.println("Overweight");
		else
			System.out.println("Obesity");
    }
}

发表于 2020-02-23 14:06:53 回复(0)