javaif-statementblackjackgambling

Is it possible to use 2 Mathematical Conditions in a If Statement?


I'm creating a blackjack program. I need to check if the dealer's hand is greater than the players hand and also less then 21.

Variables

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

I tried doing this :

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

But I received the following errors : Type mismatch : cannot convert from int to boolean. The operator && is undefined for the argument types boolean, int.

If anyone could possible suggest another way to do this, or if I'm just simply making a syntax mistake, I'd really appreciate it.

TO CLARIFY: I wanted to check if the value of the dealer's card is greater then the player's cards, but also less than 21.


Solution

  • You have to split condition into two.

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