首页 > 试题广场 >

衡量人体胖瘦程度

[编程题]衡量人体胖瘦程度
  • 热度指数:20144 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
在计算BMIBodyMassIndex ,身体质量指数)的案例基础上,判断人体胖瘦程度。BMI中国标准如下表所示。




输入描述:
多组输入,每一行包括两个整数,用空格隔开,分别为体重(公斤)和身高(厘米)。


输出描述:
针对每行输入,输出为一行,人体胖瘦程度,即分类。
示例1

输入

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);
        }
    }
}

发表于 2022-03-19 12:39:54 回复(0)
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");
            }
        }
    }
}

发表于 2022-01-27 20:01:25 回复(0)
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");
            }
        }
    }
}

发表于 2021-12-14 01:54:50 回复(0)
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");
            }
        }
    }
}

发表于 2021-09-29 10:58:36 回复(0)
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";
  }
}

发表于 2021-08-15 20:58:48 回复(0)
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        while(input.hasNext()){
            double a = input.nextDouble();
            double b = input.nextDouble();
            double bmi=a*10000/(b*b);
            if(bmi<18.5) System.out.println("Underweight");
            if(bmi<=23.9&&bmi>18.5) System.out.println("Normal");
            if(bmi<=27.9&&bmi>23.9) System.out.println("Overweight");
            if(bmi>27.9) System.out.println("Obese");
        }
    }
}

发表于 2020-10-29 20:59:25 回复(0)