2010-10-20 25 views
0

Faire un code Java simple pour Blackjack et besoin de quelques conseils.Alors que la question au Blackjack

OK J'essaie de faire cette boucle et d'arrêter quand je dis "rester" des suggestions ??

while (name4.equals("stay")) 
{ 
    System.out.print("Would you like to hit or stay? "); 
    String name4 = keyboard.next(); 

    total2 = total+number4; 
    number4 = random.nextInt(9)+2; 

    System.out.println("You drew a " + number4 + ". "); 
    System.out.println("Your total is " + (total + number4) + ". "); 

    if (total == 21) 
    { 
      System.out.print("YOU WIN!"); 
    } 

} 

Répondre

1

Ajoutez simplement un !.

Votre expression de boucle while en langage simple: alors que name4 n'est pas égal à "rester", continuez la boucle.

while (!name4.equals("stay")) 
{ 
    System.out.print("Would you like to hit or stay? "); 
    String name4 = keyboard.next(); 

    total2 = total+number4; 
    number4 = random.nextInt(9)+2; 

    System.out.println("You drew a " + number4 + ". "); 
    System.out.println("Your total is " + (total + number4) + ". "); 

    if (total == 21) 
    { 
      System.out.print("YOU WIN!"); 
    } 

}