【问题标题】:')' expected error with if-else statements, including &&s [closed]')' if-else 语句的预期错误,包括 &&s [关闭]
【发布时间】:2013-10-20 00:03:27
【问题描述】:

所以我有多个 if-else 语句,所以如果用户是 m/f 以及他们选择什么选择来决定他们的 tdee。

这是一段代码:

    else if (gender.equalsIgnoreCase("M") && (choice.equalsIgnoreCase("C"))
    {
    activityFactor = 1.6;
    }
    else if (gender.equalsIgnoreCase("F") && (choice.equalsIgnoreCase("C"))    
    {
    activityFactor = 1.5;
    }

【问题讨论】:

  • 你是在暗示女性不如男性活跃吗?反之亦然?
  • 为什么块开始是else?
  • @lealand 我选择让 Jerome 从怀疑中受益,并假设这是因为他将问题追踪到了这些行,并且在实际完整代码中上面有一些 if。
  • 这个问题似乎是题外话,因为它是一个错字

标签: java if-statement


【解决方案1】:

您不需要额外的(。与&&无关

else if (gender.equalsIgnoreCase("M") && choice.equalsIgnoreCase("C"))

) 的数量必须与 ( 的数量相同。

【讨论】:

    【解决方案2】:
    else if (gender.equalsIgnoreCase("M") && choice.equalsIgnoreCase("C"))
    {
    activityFactor = 1.6;
    }
    else if (gender.equalsIgnoreCase("F") && choice.equalsIgnoreCase("C"))    
    {
    activityFactor = 1.5;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-18
      • 1970-01-01
      • 1970-01-01
      • 2020-07-26
      • 2017-09-05
      相关资源
      最近更新 更多