- import java.io.Console;
- public class BMI //類別
- {
- public static void main(String args[])
- {
- float x,y;
- Console console=System.console();
- String name; //名字
- System.out.print("請輸入姓名");
- name=console.readLine();
- System.out.print("請輸入身高(單位cm)");
- x=Float.parseFloat(console.readLine());
- System.out.print("請輸入體重(單位kg)");
- y=Float.parseFloat(console.readLine());
- if(y/((x/100)*(x/100))>=35)
- {
- System.out.println("親愛的"+name+",您的BMI值為"+y/((x/100)*(x/100))+"重度肥胖");
- }else if(y/((x/100)*(x/100))>=30 && y/((x/100)*(x/100))<35)
- {
- System.out.println("親愛的"+name+",您的BMI值為"+y/((x/100)*(x/100))+"中度肥胖");
- }else if(y/((x/100)*(x/100))>=27 && y/((x/100)*(x/100))<30)
- {
- System.out.println("親愛的"+name+",您的BMI值為"+y/((x/100)*(x/100))+"輕度肥胖");
- }else if(y/((x/100)*(x/100))>=25 && y/((x/100)*(x/100))<27)
- {
- System.out.println("親愛的"+name+",您的BMI值為"+y/((x/100)*(x/100))+"過重");
- }else if(y/((x/100)*(x/100))>=(18.5) && y/((x/100)*(x/100))<24)
- {
- System.out.println("親愛的"+name+",您的BMI值為"+y/((x/100)*(x/100))+"正常範圍");
- }
- else
- {
- System.out.println("親愛的"+name+",您的BMI值為"+y/((x/100)*(x/100))+"體重過輕!");
- }
- }
- }
複製代碼 |