java - token 语法错误 "(", ;预期的

标签 java syntax-error

所以我正在 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;
 }

关于java - token 语法错误 "(", ;预期的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28264776/

相关文章:

shell - Shell脚本中IF语句中的OR条件

java - Spring data redis - 多模式 - 在 session 中更改模式(获取连接)VS。使用多个连接池

c - 这段代码有什么问题? (基本 C 代码)

syntax-error - 如何在sikuli中使用keyDown()和keyUp()?

java - 数组和 if 语句 : Array object not passable into if statement

makefile - Makefile配方语法错误中的负球

python - 试图找出为什么我在第 12 行收到打印语法错误

java - JRuby 到 jar 可执行文件

java - Java中的窗口操作通知

java - JList 文本对齐