参考这个写吧:
import java.util.Scanner;
public class BMIIndex {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("##########BIM检测##########");
System.out.print("请输入您的体重:");
double weight = sc.nextDouble();
System.out.print("请输入您的身高:");
double stature = sc.nextDouble();
double BMI = weight / (stature * stature);
if (BMI < 18) {
System.out.println("\n提示:您的BMI值为:" + String.format("%.2f", BMI) + ",测量结果为体重偏轻!");
} else if (BMI > 18 && BMI <= 25) {
System.out.println("\n提示:您的BMI值为:" + String.format("%.2f", BMI) + ",测量结果为体重正常!");
} else if (BMI > 25 && BMI <= 30) {
System.out.println("\n提示:您的BMI值为:" + String.format("%.2f", BMI) + ",测量结果为超重!");
} else if (BMI > 30 && BMI <= 35) {
System.out.println("\n提示:您的BMI值为:" + String.format("%.2f", BMI) + ",测量结果为轻度肥胖!");
} else if (BMI > 35 && BMI <= 40) {
System.out.println("\n提示:您的BMI值为:" + String.format("%.2f", BMI) + ",测量结果为中度肥胖!");
} else if (BMI > 40) {
System.out.println("\n提示:您的BMI值为:" + String.format("%.2f", BMI) + ",测量结果为高度肥胖!");
}
sc.close();
}
}