import java.util.Scanner;
public class Test {
public static void main(String[] args) {
/*
* 请用if ... else编写一个程序,用于计算体质指数BMI,并打印结果。
*
* BMI = 体重(kg)除以身高(m)的平方
* BMI结果:
* 过轻:低于18.5 正常:18.5-25 过重:25-28 肥胖:28-32 非常肥胖:高于32
*/
// 1.获取Scanner键入对象(double)
var scanner = new Scanner(System.in);
// 2.获取体重(double),身高(double)对象
System.out.println("请输入您的体重(KG):");
var weight = scanner.nextDouble();
System.out.println("请输入您的身高(m):");
var height = scanner.nextDouble();
// 3.获取(Double)BMI=weight/height
double bim = weight / (height * height);
// 4.使用if语句: 过轻:低于18.5 正常:18.5-25 过重:25-28 肥胖:28-32 非常肥胖:高于32
if (bim < 18.5) {
System.out.println("过轻");
} else if (bim > 18.5 && bim < 25) {
System.out.println("正常");
} else if (bim > 25 && bim < 28) {
System.out.println("过重");
} else if (bim > 28 && bim < 32) {
System.out.println("肥胖");
} else if (bim > 32) {
System.out.println("非常胖");
}
System.out.printf("您的BIM值:%.1f", bim);
Sign in to make a reply
健豪豪_486
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
/*
* 请用if ... else编写一个程序,用于计算体质指数BMI,并打印结果。
*
* BMI = 体重(kg)除以身高(m)的平方
*
* BMI结果:
*
* 过轻:低于18.5 正常:18.5-25 过重:25-28 肥胖:28-32 非常肥胖:高于32
*/
// 1.获取Scanner键入对象(double)
var scanner = new Scanner(System.in);
// 2.获取体重(double),身高(double)对象
System.out.println("请输入您的体重(KG):");
var weight = scanner.nextDouble();
System.out.println("请输入您的身高(m):");
var height = scanner.nextDouble();
// 3.获取(Double)BMI=weight/height
double bim = weight / (height * height);
// 4.使用if语句: 过轻:低于18.5 正常:18.5-25 过重:25-28 肥胖:28-32 非常肥胖:高于32
if (bim < 18.5) {
System.out.println("过轻");
} else if (bim > 18.5 && bim < 25) {
System.out.println("正常");
} else if (bim > 25 && bim < 28) {
System.out.println("过重");
} else if (bim > 28 && bim < 32) {
System.out.println("肥胖");
} else if (bim > 32) {
System.out.println("非常胖");
}
System.out.printf("您的BIM值:%.1f", bim);
}
}