2016-12-04 84 views
-2

我正试图让方法互相调用并生成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

其中要调用的bodyMassIndex静态方法后? – Shriram

+0

我不是atm - 那正是我想要做的 – Jt8146

回答

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); 

} 

}

0

从用户读取公斤呼叫的方法bodyMassIndex

System.out.println("Enter weight (KG): "); 
kg = input.nextDouble(); 

System.out.println("Enter height (M): "); 
m = input.nextDouble(); 

bodyMassIndex(kg, m); 
相关问题