【问题标题】:Is it possible to use 2 Mathematical Conditions in a If Statement?是否可以在 If 语句中使用 2 个数学条件?
【发布时间】:2018-09-26 18:17:33
【问题描述】:

我正在创建一个二十一点程序。我需要检查if the dealer's hand is greater than the players handand also less then 21.

变量

dValue1 is the dealer's first card
dValue2 is the dealer's second card
pValue1 is the player's first card
pValue2 is the player's second card

我试过这样做:

if(dValue1 + dValue2 > pValue1 + pValue2 && < 21)

但我收到以下错误: 类型不匹配:无法从 int 转换为 boolean。 对于参数类型 boolean、int,运算符 && 未定义。

如果有人可以建议另一种方法来做到这一点,或者如果我只是犯了一个语法错误,我将不胜感激。

澄清:我想检查庄家的牌值是否大于玩家的牌,但也小于 21。

【问题讨论】:

  • 可能是... &amp;&amp; dValue1 + dValue2 &lt; 21),但如果您提供minimal reproducible example 包括您使用的语言会有所帮助。

标签: java if-statement blackjack gambling


【解决方案1】:

你必须将条件一分为二。

if ((dValue1 + dValue2) > (pValue1 + pValue2) && (dValue1 + dValue2) < 21)

【讨论】:

  • 谢谢!这行得通。我很确定我只是语法错误。珍惜帮助伙伴!
猜你喜欢
  • 2012-10-10
  • 2021-09-02
  • 2021-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-06
  • 2012-02-05
相关资源
最近更新 更多