Discuss / Java / 作业

作业

Topic source
import java.util.Scanner;

public class Test{
    public static void main(String[] args) {
    	Scanner scanner = new Scanner(System.in);
    	System.out.print("身高(m):");
    	double height = scanner.nextDouble();
       	System.out.print("体重(kg):");
    	double weight = scanner.nextDouble();

        double bmi = weight / (height*height);
        String status;
        
        if (bmi > 32){
        	status = "非常肥胖";
        }else if (bmi>28&&bmi<=32){
        	status = "肥胖";
        }else if (bmi>25&&bmi<=28){
        	status = "过重";
        }else if (bmi>18.5&&bmi<=25){
        	status = "正常";
        }else if (bmi<=18.5){
        	status = "过轻";
        }

    	System.out.printf("您的BMI为%.2f, 情况为%s。", bmi, status);
    }
}

  • 1

Reply