import java.util.Scanner;
Scanner scanner = new Scanner(System.in); // 创建Scanner对象
System.out.print("Input your weight(Kg): "); // 打印提示
double weight = scanner.nextDouble(); // 读取一行输入并获取字符串
System.out.print("Input your height(m): "); // 打印提示
double tall = scanner.nextDouble(); // 读取一行输入并获取整数
double BMI = weight / (tall*tall);
System.out.printf("Hi, your BMI is %.2f\n",BMI); // 格式化输出
if (BMI < 18.5) {
System.out.println("too light.");
}else if (BMI>=18.5 && BMI<25) {
System.out.println("normal");
}else if (BMI>=25 && BMI<28) {
System.out.println("too heavy");
}else if (BMI>=28 && BMI<32) {
System.out.println("fat");
}else {
System.out.println("too fat");
}
Sign in to make a reply
爱竹子的大黑熊
import java.util.Scanner;
Scanner scanner = new Scanner(System.in); // 创建Scanner对象
System.out.print("Input your weight(Kg): "); // 打印提示
double weight = scanner.nextDouble(); // 读取一行输入并获取字符串
System.out.print("Input your height(m): "); // 打印提示
double tall = scanner.nextDouble(); // 读取一行输入并获取整数
double BMI = weight / (tall*tall);
System.out.printf("Hi, your BMI is %.2f\n",BMI); // 格式化输出
if (BMI < 18.5) {
System.out.println("too light.");
}else if (BMI>=18.5 && BMI<25) {
System.out.println("normal");
}else if (BMI>=25 && BMI<28) {
System.out.println("too heavy");
}else if (BMI>=28 && BMI<32) {
System.out.println("fat");
}else {
System.out.println("too fat");
}