- import java.util.Scanner;
- public class BMI
- {
- public static void main (String args[])
- {
- Scanner s = new Scanner(System.in);
- float weight , height , BMI;
- System.out.print("請輸入您的身高cm(整數): ");
- height = s.nextFloat()/100;
- while(height>2.5 || height <0.5)
- {
- System.out.print("您輸入的身高(cm)有誤,請重新輸入: ");
- height = s.nextFloat()/100;
- }
- System.out.println() ;
- System.out.println() ;
- System.out.println("您的身高為:"+(height*100)+"cm") ;
- System.out.print("請輸入您的體重kg(整數): ");
- weight = s.nextFloat();
- while(weight>250 || weight <0)
- {
- System.out.print("您輸入的體重(kg)有誤,請重新輸入: ");
- weight = s.nextFloat();
- }
- System.out.println("您的體重為:"+weight+"kg") ;
- System.out.println("計算中.....") ;
- BMI = weight / ( height * height );
- System.out.println("┌────────────────┐") ;
- System.out.println("│您的身高為: "+(height*100)+"(cm) │") ;
- System.out.println("│您的體重為: "+weight+"(kg) │") ;
- System.out.println("└────────────────┘") ;
- System.out.println("================================") ;
- System.out.println("您的BMI值為: "+BMI) ;
- if(BMI >= 35)
- {
- System.out.println("診斷結果:重度肥胖") ;
- }else if(BMI<35 && BMI>=30)
- {
- System.out.println("診斷結果:中路肥胖") ;
- }else if(BMI<30 && BMI>=27)
- {
- System.out.println("診斷結果:輕度肥胖") ;
- }else if(BMI<27 && BMI>=24)
- {
- System.out.println("診斷結果:過重") ;
- }else if(BMI<24 && BMI>=18.5)
- {
- System.out.println("診斷結果:恭喜您在正常範圍") ;
- }else if(BMI<18.5 && BMI>0)
- {
- System.out.println("診斷結果:體重過輕") ;
- }else
- {
- System.out.println("輸入有誤請重新檢查") ;
- }
- System.out.println("================================") ;
- }
- }
複製代碼 |