Discuss / Java / 练习

练习

Topic source

#1 Created at ... [Delete] [Delete and Lock User]

import java.util.Scanner;

public class BMI {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner scanner = new Scanner(System.in);

System.out.println("请输入你的体重(kg):");

float weight = scanner.nextFloat();

System.out.println("请输入你的身高(m):");

float stature = scanner.nextFloat();

scanner.close();

float bmi = weight/(stature*stature);

System.out.println("你的BMI为:" + bmi);

if (bmi < 18.5f) {

System.out.println("你的体重为:过轻");

}else if (18.5f <= bmi && bmi <= 23.9f) {

System.out.println("你的体重为:正常" );

}else if (24.0f <= bmi && bmi <= 27.9f) {

System.out.println("你的体重为:过重" );

}else if (28.0f <= bmi && bmi <= 32.0f) {

System.out.println("你的体重为:肥胖" );

}else {

System.out.println("你的体重为:过度肥胖" );

}

}

}


  • 1

Reply