问题及代码:
/*
*Copyright (c)2015,西南大学计信院
*All rights reserved.
*文件名称:ComputeBMI.java
*作 者:高硕
*完成日期:2015年10月16日
*版 本 号:v1.0
*问题描述:计算健康指数。
*程序输入:体重身高。
*程序输出:根据结果输出判定情况。
*/
package practice_01;
import java.util.Scanner;
public class ComputeBMI {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input =new Scanner(System.in);
System.out.println("input the weight");
double weight=input.nextDouble();
System.out.println("input the height");
double height=input.nextDouble();
final double KILOGRAMS_PER_POUND = 0.45359237; // Constant
final double METERS_PER_INCH = 0.0254; // Constant
double weightInKilogram = weight * KILOGRAMS_PER_POUND;
double heightInMeters = height * METERS_PER_INCH;
double bmi = weightInKilogram /
(heightInMeters * heightInMeters);
System.out.printf( "your BMI is %5.2f\n", bmi);//printf
if(bmi<16)
System.out.println("You are seriously underweight");
else if (bmi < 18)
System.out.println("You are underweight");
else if (bmi < 24)
System.out.println("You are normal weight");
else if (bmi < 29)
System.out.println("You are overweight");
else if (bmi < 35)
System.out.println("You are seriously overweight");
else
System.out.println("You are gravely overweight");
}
}
运行结果:
知识点总结:
if else if 语句。
心得及体会:
if条件语句和其他语言并没有什么区别。还有原来能用printf,用法和c一样。
今天有点困,要早睡了~~