Tuesday, 15 April 2014

java - while loop if statements -


I have found this work almost completely, I can not manage to get it:

< P> if the player either sticks or busts (player (pscore & lt; = card1 + card2)) to the statement

What I can see, this should work ... but I am missing an extension, and I do not know what that is.

  import java.util.Random; Import java.util.Scanner; Class Blackjack {Public Static Zero Main (String [] Args) {Random R = New Random (); String name; Scanner scanner = new scanner (System.in); Boolean Your Turn = True; Boolean dealers turn = true; Int card1 = 1 + r.nextInt (11); Int card2 = 1 + r.nextInt (11); Int dcard1 = 1 + r.nextInt (11); Int dcard2 = 1 + r.nextInt (11); Int pscore = card1 + card2; Int dscore = dcard1 + dcard2; System.out.println ("Welcome to Blackjack!"); System.out.println ("Close to 21 without moving forward \ n"); System.out.println ("What is your name?"); Name = scannerIn.nextLine (); System.out.println ("\ n Halo" + name); System.out.println ("\ nLet's play some black jack!"); System.out.println ("\ n Dealer Reveals: \ t" + dcard1); System.out.println ("\ n \ nYour first card is: \ t" + card1); System.out.println ("\ n your second card is: \ t" + 2 cards); System.out.println ("\ nA large amount of you give:" + pscore); While (your turn) {if (pscore and lt; = + card1 + card2)) System.out.println ("\ n Do you want to tick it (h) or (s)?"); String A = scanner in. Nxtine (); If (A.Torcas (.) Equals ("H")) {int newCard = 1 + r.nextInt (11); System.out.println ("\ n your next card" + new card); Pscore = pscore + newcard; System.out.println ("\ nby giving a new total of" + pscore "); if ((pscore> = 22)) {System.out.println (" \ nBuilding! \ N Sorry! , You lost "); your turn = wrong; break;}} and if (a.toLowerCase (.) Equals (" s ") {yourTurn = false; System.out.println (" \ nYou "+ pscore Paste on); System.out.println ("\ n Now it's the turn of dealers \ nThe dealer should draw up to 17");} Else {System.out.println ("\ nPlease press H or S"); } While dealers (turners) {dealersTurn = true; {If ((dscore & lt; = dcard1 + dcard2)) System.out.println ("\ n Dealer cards were: \ n" + dcard1); System.out.println ("\ Nand \ n" + dcard2); System.out.println ("\ n Dealer One vs. Give total: "+ dscore);} {Int newCard1 = 1 + r.nextInt (11); if ((dscore & lt; = 17)) System.out.println (" \ n Dealer has come: "+ newCard1 ); Dscore = dscore + newCard1; System.out.println ("\ nGive the dealer a huge total:" + dscore);} if ((dscore> = 22)) {System.out.println (" N Dialer Bust! "); System.out.println (" \ "loses House"); System.out.println ("\ nYou Win"); DealersTurn = false; Break; } And if ((dscore> = pscore)} {System.out.println ("\ ndeller" + dscore); System.out.println ("\ n Dealer Defeat You!"); System.out.println ("\ nThe house wins!"); DealersTurn = false; Break; }}} ScannerIn.close (); }}  

Besides, I have to thank a lot of people, which helps me overcome it. If people have a +1 button, I can not find it.

Thanks for the help Vincent.

Your time (yourTurn) loop does not shut down the bracket until the (dealership) loop. This causes dealers to become a part of your turn loop. Add a closing bracket above the dealers, while the loop is turned on:

 } while (dealersor) { 

then from the downstream to the old closing bracket

  if ((pscore & lt; = + card1 + card2)) 

But also, what is the purpose of your logic? Code>

Your score = 1 card is 1 + card 2 and then if you remove another card you will have more than 2 cards because you have 3 cards. This is why it is your B The vehicle is not entering.


No comments:

Post a Comment