import java.util.Scanner; public class Assignment2 { private static double w1; private static double w2; private static double BMI; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("下面开始计算体重指数"); System.out.println("请输入你的身高(cm|m)"); double height = scanner.nextDouble(); System.out.println("请输入体重(Kg)"); double weight = scanner.nextInt(); if (height != (int) height) { BMI = weight / Math.pow(height, 2); System.out.printf("你的体重指数(BMI)为%.2f%n", BMI); w1 = Math.pow(height, 2) * 18.5; w2 = Math.pow(height, 2) * 25; A(); } else { BMI = weight / Math.pow(height / 100, 2); System.out.printf("你的体重指数(BMI)为%.2f%n", BMI); w1 = Math.pow(height / 100, 2) * 18.5; w2 = Math.pow(height / 100, 2) * 25; A(); } } private static void A() { if (BMI <= 18.5) { System.out.println("体重过轻了"); System.out.printf("建议体重为%.2fKg~%.2fKg", w1, w2); } else if (BMI > 18.5 && BMI <= 25) { System.out.println("恭喜你,你的体重正常"); System.out.printf("请继续保持%.2fKg~%.2fKg", w1, w2); } else if (BMI > 25 && BMI <= 28) { System.out.println("你的体重偏胖"); System.out.printf("建议体重为%.2fKg~%.2fKg", w1, w2); } else if (BMI > 28 && BMI <= 32) { System.out.println("你的体重肥胖"); System.out.printf("建议体重为%.2fKg~%.2fKg", w1, w2); } else if (BMI > 32) { System.out.println("你的体重非常肥胖"); System.out.printf("建议体重为%.2fKg~%.2fKg", w1, w2); } } }
Sign in to make a reply
j柠檬e族