Java 如何将程序语句参数(如heightm)传递给其他方法?

Java 如何将程序语句参数(如heightm)传递给其他方法?,java,oop,Java,Oop,} 我试图让代码传递语句,但我是编程新手,不知道如何将方法传递给另一个方法。我试着到处找,但没找到什么帮助。请提供帮助,这样我就可以使我的程序正常运行。我很高兴学习,但我需要帮助。您可以尝试将变量设置为全局范围(方法之外)。您可以了解它。您可以尝试为变量指定全局范围(方法之外)。您可以了解它。当您在方法(即代码块)中声明变量时,它是该块的局部变量。因此,您不能在任何其他方法中使用该变量。在这里,最好的选择是将变量声明为类变量,如weightkg等。当您在方法(即代码块)中声明变量时,它是该块的局

}


我试图让代码传递语句,但我是编程新手,不知道如何将方法传递给另一个方法。我试着到处找,但没找到什么帮助。请提供帮助,这样我就可以使我的程序正常运行。我很高兴学习,但我需要帮助。

您可以尝试将变量设置为全局范围(方法之外)。您可以了解它。

您可以尝试为变量指定全局范围(方法之外)。您可以了解它。

当您在方法(即代码块)中声明变量时,它是该块的局部变量。因此,您不能在任何其他方法中使用该变量。在这里,最好的选择是将变量声明为类变量,如weightkg等。

当您在方法(即代码块)中声明变量时,它是该块的局部变量。因此,您不能在任何其他方法中使用该变量。在这里,最好的选择是声明变量,例如weightkg等作为类变量。

您可以将方法的返回类型从void更改为double,并存储返回的结果,然后将结果发送给其他方法。 例如


您可以将方法的返回类型从void更改为double,并存储返回的结果并将结果发送给其他方法。 例如


您可能需要阅读定义“program statement argument”。您可能需要阅读定义“program statement argument”。现在我尝试从main方法中获取变量并将其放入其他方法参数中如何?现在我尝试从main方法中获取变量并将其放入其他方法中参数
import java.util.Scanner ;

public class CollinsHealthCalculator {

double ACTIVITY_FACTOR = 1.375;

public static void main (String[] args) {
    newHealthCalcDescription ();
    Scanner keyboard = new Scanner (System.in);
    System.out.println ("What is your weight in pounds? ");
    double weightlb = keyboard.nextDouble ();
    System.out.println ("What is your height in inches? ");
    double heightin = keyboard.nextDouble ();
    System.out.println ("What is your age in years? ");
    double ageYears = keyboard.nextDouble (); 
    double WEIGHT_KILOGRAMS = weightlb / 2.2;
    double HEIGHT_METERS = heightin * .0254;
    double weightkg = WEIGHT_KILOGRAMS;
    double heightm = HEIGHT_METERS;
    double computingBMI (BMI, weightkg, heightm);      
    maleBMR (heightm, weightkg, ageYears);
    femaleBMR (heightm, weightkg, ageYears);
    showResults (BMI, caloriesm, caloriesf);         

public static newHealthCalcDescription () {
    System.out.println("This calculator will determine your BMI "
            + "(Body Mass Index). While also it will determine the amount "
            + "of calories needed to maintain weight.");
}
    //Computing the BMI
public static void computingBMI (double BMI, double weightkg, double heightm){

    BMI = weightkg/(Math.pow(heightm, 2));

}
    //Computing BMR for male and female
public static void maleBMR (double heightm, double weightkg, double ageYears) {
    double HEIGHT_CENTIMETERS = heightm * 100;
    double heightcm = HEIGHT_CENTIMETERS ;
    double BMRForMales = 13.397 * weightkg + 4.799 * heightcm - 5.677 * ageYears + 88.362;
    double caloriesm = Math.round(BMRForMales * 1.375); 
}

public static void femaleBMR (double heightm, double weightkg, double ageYears) {
    double HEIGHT_CENTIMETERS = heightm * 100;
    double heightcm = HEIGHT_CENTIMETERS ;
    double BMRForFemales = 9.247 * weightkg + 3.098 * heightcm - 4.330 * ageYears + 447.593;
    double caloriesf = Math.round(BMRForFemales * 1.375);
}
public static void showResults (double BMI, double caloriesm, double caloriesf) {
    //Show results
    System.out.printf ("%nYour BMI is: %7.1f", BMI);
    System.out.println ("A BMI between 18.5 to 24.9 is considered normal.");
    System.out.println ();
    System.out.println ("To maintain current weight:");
    System.out.print ("Men need to eat " + caloriesm);
    System.out.println (" calories per day.");
    System.out.print ("Females need to eat " + caloriesf);
    System.out.println (" calories per day.");       
}
public static double computingBMI (double BMI, double weightkg, double heightm){

  return weightkg/(Math.pow(heightm, 2));

}