Java 尝试用循环计算BMI?

Java 尝试用循环计算BMI?,java,methods,return,Java,Methods,Return,我必须做一个程序,循环五个人的BMI,我使用扫描仪输入姓名、体重和身高,但我似乎无法返回输出。我用多种方法工作 程序应该是这样的: 我所拥有的只是: public static void main(String[] args) { Scanner sc = new Scanner(System.in); int i; System.out.println("How many BMIs do you want to compute? " + 5

我必须做一个程序,循环五个人的BMI,我使用扫描仪输入姓名、体重和身高,但我似乎无法返回输出。我用多种方法工作

程序应该是这样的:

我所拥有的只是:

public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int i;

        System.out.println("How many BMIs do you want to compute? " + 5);

        for (i = 1; i <= 5; ++i) {

            System.out.println("\n\nLoop " + i + " out of " + 5);

            System.out.print("Client's first name: ");
            String firstName = sc.next().toLowerCase();

            System.out.print("Client's weight in pounds: ");
            double weight = sc.nextDouble();

            System.out.print("Client's height in inches: ");
            double height = sc.nextDouble();

            return;
        }



        sc.close();
    }


    public static double computeBMI(double weight, double height) {

        double bmi = ((weight * 703) / Math.pow(height, 2));

        if (bmi < 18.5 ) {
            System.out.println("underweight.\n");
        }
        else if ( (bmi >= 18.5) && (bmi < 25) ) {
            System.out.println("normal weight.\n");
        }
        else if ( (bmi >= 25) && (bmi < 30) ) {
            System.out.println("overweight.\n");
        }
        else {
            System.out.print("obese.\n");
        }

        return bmi;

    }


    public static String printResult(String firstName, double bmi) {

        double weight;
        double height;

        System.out.printf("\nDear %s, your BMI is %.1f and you are ", firstName, bmi);
我该怎么做呢?

用以下内容替换主管道。就您当前的代码而言,您甚至没有对定义的方法设置上限

public static void main(String[] args) {

 Scanner sc = new Scanner(System.in);

 int i;

 System.out.println("How many BMIs do you want to compute? " + 5);

 for (i = 1; i <= 5; ++i) {

  System.out.println("\n\nLoop " + i + " out of " + 5);

  System.out.print("Client's first name: ");
  String firstName = sc.next().toLowerCase();

  System.out.print("Client's weight in pounds: ");
  double weight = sc.nextDouble();

  System.out.print("Client's height in inches: ");
  double height = sc.nextDouble();

  printResult(firstName, (computeBMI(wight, height))); //HERE
 }
 sc.close();
 return;
}

你从来没有调用computeBMI或printResult。你甚至没有调用Methods。你所说的调用是什么意思?在其他方法内部?并且您正在返回for loopYes,replace return的内部;带有printResultfirstName、computeBMI重量、高度;