- import java.lang.*;
- import java.util.Scanner;
- public class bmi{
- public static void main(String args[]){ //也可用 pigs
- Scanner s = new Scanner(System.in);
- System.out.print("請輸入您的身高:");
- float height = s.nextFloat();
- System.out.print("請輸入您的體重:");
- int weight = s.nextInt();
- height = height/100;
- float bmi = weight/(height*height);
- System.out.println(bmi);
- if(bmi<18.5){
- System.out.println("體重過輕");
- }else if (bmi>=18.5 && bmi<24){
- System.out.println("正常範圍");
- }else if(bmi>=24 && bmi<27){
- System.out.println("過重");
- }else if (bmi>=27 && bmi<30){
- System.out.println("輕度肥胖");
- }else if (bmi>=30 && bmi<35){
- System.out.println("中度肥胖");
- }else{
- System.out.println("重度肥胖");
- }
- }
- }
複製代碼 |