我试图让方法相互调用并产生bmi计算。如何将这些方法链接在一起以便打印bmi计算?
public class BodyMassIndex {
public static String bodyMassIndex(double weight, double height)
{
double bmi = weight / (height*height);
if (bmi < 16)
System.out.println("Seriously underweight");
else if (bmi >= 16 && bmi < 18)
System.out.println("Underweight");
else if (bmi >= 18 && bmi < 24)
System.out.println("Normal weight");
else if (bmi >= 24 && bmi < 29)
System.out.println("Overweight");
else if (bmi >= 29 && bmi < 35)
System.out.println("Seriously overweight");
else if (bmi >= 35 )
System.out.println("Obese");
return null;
}
public static void main(String[] args){
double m;
double kg;
Scanner input = new Scanner(System.in);
System.out.println("Enter weight (KG): ");
kg = input.nextDouble();
System.out.println("Enter height (M): ");
m = input.nextDouble();
}
我的代码如上所示。
答案 0 :(得分:0)
public class BodyMassIndex {
public static void bodyMassIndex(double weight, double height)
{
double bmi = weight / (height*height);
if (bmi < 16)
System.out.println("Seriously underweight");
else if (bmi >= 16 && bmi < 18)
System.out.println("Underweight");
else if (bmi >= 18 && bmi < 24)
System.out.println("Normal weight");
else if (bmi >= 24 && bmi < 29)
System.out.println("Overweight");
else if (bmi >= 29 && bmi < 35)
System.out.println("Seriously overweight");
else if (bmi >= 35 )
System.out.println("Obese");
}
public static void main(String[] args){
double m;
double kg;
Scanner input = new Scanner(System.in);
System.out.println("Enter weight (KG): ");
kg = input.nextDouble();
System.out.println("Enter height (M): ");
m = input.nextDouble();
bodyMassIndex(kg, m);
}
}
答案 1 :(得分:0)
在阅读用户 kg 和 m 后,调用方法 bodyMassIndex
System.out.println("Enter weight (KG): ");
kg = input.nextDouble();
System.out.println("Enter height (M): ");
m = input.nextDouble();
bodyMassIndex(kg, m);