在计算BMI(BodyMassIndex ,身体质量指数)的案例基础上,判断人体胖瘦程度。BMI中国标准如下表所示。
多组输入,每一行包括两个整数,用空格隔开,分别为体重(公斤)和身高(厘米)。
针对每行输入,输出为一行,人体胖瘦程度,即分类。
80 170 60 170 90 160 50 185
Overweight Normal Obese Underweight
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
/**
* @Title: 衡量人体胖瘦程度
* @Remark: 在计算BMI(BodyMassIndex ,身体质量指数)的案例基础上,判断人体胖瘦程度。
* 输入描述:
* 多组输入,每一行包括两个整数,用空格隔开,分别为体重(公斤)和身高(厘米)。
* 输出描述:
* 针对每行输入,输出为一行,人体胖瘦程度,即分类。
*
* @Author: ijunfu
* @Version: 1.0.0
* @Date: 2022-03-19
*/
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextLine()) {
List<Integer> list = Arrays.stream(in.nextLine().split(" ")).map(x -> Integer.valueOf(x)).collect(Collectors.toList());
int w = list.get(0);
int h = list.get(1);
double bmi = w / Math.pow(h/100.0, 2);
String str = "";
if(bmi <18.5) {
str = "Underweight";
} else if(18.5<= bmi && bmi <= 23.9) {
str = "Normal";
} else if(23.9< bmi && bmi <= 27.9) {
str = "Overweight";
} else {
str = "Obese";
}
System.out.println(str);
}
}
}
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sin = new Scanner(System.in);
while(sin.hasNext()){
long w = sin.nextInt(); // 体重
double h = sin.nextInt(); // 身高 必须使用double 来接收不然计算精度或变化
double d = h / 100; // 把身高变成厘米
double bml = w / (d * d); // 计算
if(bml < 18.5){
System.out.println("Underweight");
}else if(bml >= 18.5 && bml <= 23.9){
System.out.println("Normal");
}else if(bml >= 23.9 && bml <= 27.9){
System.out.println("Overweight");
}else if(bml > 27.9){
System.out.println("Obese");
}
}
}
} import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNextLine()){
String str = scanner.nextLine();
String[] s = str.split(" ");
double n = Double.parseDouble(s[1]) / 100;
int m = Integer.parseInt(s[0]);
double d = n*n;
double BMI = m / d;
if (BMI < 18.5){
System.out.println("Underweight");
}else if (BMI >= 18.5 && BMI <= 23.9){
System.out.println("Normal");
}else if(BMI > 23.9 && BMI <= 27.9){
System.out.println("Overweight");
}else {
System.out.println("Obese");
}
}
}
} import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int weight = sc.nextInt();
int height = sc.nextInt();
double h = (double)(height/100.0);
double BMI = weight/(h*h);
if(BMI < 18.5){
System.out.println("Underweight");
}else if(BMI >= 18.5 && BMI <= 23.9){
System.out.println("Normal");
}else if(BMI >= 23.9 && BMI <= 27.9){
System.out.println("Overweight");
}else{
System.out.println("Obese");
}
}
}
} import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
Integer w = sc.nextInt();
Integer h = sc.nextInt();
System.out.println(BMI(w,h));
}
}
public static String BMI(Integer weight,Integer height){
Double h= (double)height/100.0;
double bmi = weight/(h*h);
if(bmi < 18.5){
return "Underweight";
}
else if(18.5<=bmi&&bmi<=23.9){
return "Normal";
}
else if(23.9<bmi&&bmi<=27.9){
return "Overweight";
}
else return "Obese";
}
}