教育路上
摘要:使用Scanner类来获取用户的输入计算后进行if多分支语句判断。以下是我们为大家整理的,相信大家阅读完后肯定有了自己的选择吧。
2021-06-06 21:07刘永莘
import java.util.Scanner; public class ComputeBMI{ public static void main(String[]args){ Scanner input=new Scanner(System.in); //Prompttheusertoenterweightinkilograms System.out.print("Enter weight in kilograms:"); double weight=input.nextDouble(); //Prompttheusertoenterheightinmeters System.out.print("Enter height in meters:"); double height=input.nextDouble(); //ComputeBMI double bmi=weight/(height*height); //Displayresult System.out.printf("Your BMI is %5.2f\n",bmi); if(bmi<16) System.out.println("You are seriously under weight"); else if(bmi<18) System.out.println("You are under weight"); else if(bmi<24) System.out.println("You are normal weight"); else if(bmi<29) System.out.println("You are over weight"); else if(bmi<35) System.out.println("You are seriously over weight"); else System.out.println("You are gravely over weight"); } }
访客的评论 2024/03/29 07:26
文中描述的是准确的吗,如何报名!