java - If Statement not working with OR operator -
so have shuffle method shuffles deck of cards. each card has dealt field either true/false depending on if has been dealt or not.
the shuffle method sets each cards dealt field false. i'm trying stop setting cards false, depending on if card in dealers/players hand.
public void shuffle(){ collections.shuffle(deck);//shuffles deck for(card card : deck){//for each card in deck if(!game.playershand.contains(card) || !game.dealershand.contains(card)){//if card not in dealers/players hand card.setdealt(false);//card no longer dealt }//end if }//end }//end shuffle
the above if statement not work. mark every card false, regardless.
if do:
public void shuffle(){ collections.shuffle(deck); for(card card : deck){ if(!game.playershand.contains(card)){ card.setdealt(false); } } }//end shuffle
it prevent card's dealt field in playershand beingness set false.
i'm not sure why || operand not working in case.
the ||
operator working fine, misunderstood
boolean x= !true || !false; system.out.println(x); // prints true
so apparently && looking
boolean x= !true && !false; system.out.println(x); // prints false
so in case be
if(!game.playershand.contains(card) && !game.dealershand.contains(card)){ ... }
it easier if negate whole expression
if(!(game.playershand.contains(card) || game.dealershand.contains(card))){ ... }
java if-statement
No comments:
Post a Comment