- import java.util.Scanner;
- public class bmi
- {
- public static void main (String args[])
- {
- Scanner s = new Scanner(System.in);
- float height, weight;
- float bmi;
- System.out.print("請輸入身高(cm):");
- height = s.nextFloat();
- System.out.print("請輸入體重(kg):");
- weight = s.nextFloat();
- if(height == 0)
- System.out.print("輸入錯誤");
- else
- {
- bmi = weight/(height/100)/(height/100);
-
- if(bmi < 18.5 && bmi > 0)
- System.out.print("bmi = "+bmi+"體重過輕");
- else if(bmi < 24 && bmi >= 18.5)
- System.out.print("bmi = "+bmi+"體重正常");
- else if(bmi < 27 && bmi >= 24)
- System.out.print("bmi = "+bmi+"過重");
- else if(bmi < 30 && bmi >= 27)
- System.out.print("bmi = "+bmi+"輕度肥胖");
- else if(bmi < 35 && bmi >= 30)
- System.out.print("bmi = "+bmi+"中度肥胖");
- else if(bmi >= 35)
- System.out.print("bmi = "+bmi+"重度肥胖");
- else
- System.out.print("輸入錯誤");
- }
- }
- }
複製代碼 |