令牌“(”, ; 预期的语法错误

Syntax error on token "(", ; expected

所以我在 CodingBat 工作,学习 Java,但它一直向我抛出以下代码的错误。

public int noTeenSum(int a, int b, int c) {
    return fixTeen(a)+fixTeen(b)+fixTeen(c);

    public int fixTeen(int x) {
        if(x<=12||x>=20||x==15||x==16)
            return x;
        return 0;
    }
}

题目目标如下:

Given 3 int values, a b c, return their sum. However, if any of the values is a teen -- in the range 13..19 inclusive -- then that value counts as 0, except 15 and 16 do not count as a teens. Write a separate helper "public int fixTeen(int n) {"that takes in an int value and returns that value fixed for the teen rule. In this way, you avoid repeating the teen code 3 times (i.e. "decomposition"). Define the helper below and at the same indent level as the main noTeenSum().

有什么建议吗?

您在 return fixTeen(a)+fixTeen(b)+fixTeen(c); 之后错过了一个 } 并且不需要最后一个 }

public int noTeenSum(int a, int b, int c) {
 return fixTeen(a)+fixTeen(b)+fixTeen(c);
}

public int fixTeen(int x) {
 if(x<=12||x>=20||x==15||x==16)
  return x;
 return 0;
 }