Java 使用公式定义并调用方法

Java 使用公式定义并调用方法,java,Java,我试图计算平均gpa,但我得到了一个错误 public static double calculateAVG(int grade, int credit) { double AVG; if (education == grade) { AVG= (grades * credits) / credits; } else { System.out.println("Default"); } return input.nextDouble(); } 无

我试图计算平均gpa,但我得到了一个错误

public static double calculateAVG(int grade, int credit) {
double AVG;
if (education == grade) {
        AVG= (grades * credits) / credits;
    }
    else {
        System.out.println("Default");
}
return input.nextDouble();
}

无法在函数调用中声明类型。更改:

BFP = calculateBFP(int gender, int age, double BMI);

另外,您可能无法返回
input.nextDouble()
,而是
BFP
变量

  • 您的整个代码应该在
    公共类中

  • 您还需要
    导入java.util.Scanner
    以使用来自 用户

  • 您的input.nextdouble()将从您那里获取输入并返回它,而不是您计算的BFP。因此
    返回BFP
  • BFP = calculateBFP(gender, age, BMI);