题解 | #衡量人体胖瘦程度#
衡量人体胖瘦程度
http://www.nowcoder.com/practice/4d604603fae94a26b59b7bc18f363bc0
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while(scan.hasNextInt()) {
int weight = scan.nextInt();
int height = scan.nextInt();
double BMI = weight / Math.pow(height * 1.0 / 100, 2);
//此处虽然可以用if语句实现,但是为了让代码更好,可以采用表驱动法
double[] BMItable = { 18.5, 23.9, 27.9, 100};
String[] degree = { "Underweight", "Normal", "Overweight", "Obese"};
for(int i = 0; i < 4; i++) {
if(BMI < BMItable[i]) {
System.out.println(degree[i]);
break;
}
}
}
}
}