Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import TerminalIO.KeyboardReader;
- import java.util.Random;
- public class BlackJack {
- public static void main (String [] Args){
- KeyboardReader reader = new KeyboardReader();
- Random generator = new Random();
- int card1;
- int card2;
- int card3;
- int card4;
- int choice;
- int over21;
- int under21;
- int game;
- int numb;
- int numb2;
- int numb3;
- System.out.print("Do you want to play a game? [1 to continute]: ");
- choice = reader.readInt();
- while(choice == 1){
- if (choice >=2){
- System.out.println("Do you quit?");
- }else{
- choice++;
- card1 = generator.nextInt(12) + 1;
- card2 = generator.nextInt(12) + 1;
- numb = card1 + card2;
- System.out.println("Here are your two cards: "+card1+ " "+card2);
- System.out.println(card1+ " and " +card2+ " are equal to " +numb);
- if(numb >21)
- System.out.println("You lose!");
- if(numb ==21)
- System.out.println("You win!");
- if(numb <=22){
- System.out.print("Do you want another card? Yes [1], No [2]: ");
- choice = reader.readInt();
- while(choice == 1){
- choice++;
- card3 = generator.nextInt(12) + 1;
- numb2 = numb + card3;
- System.out.println("You got a " +card3);
- System.out.println("Your cards add up to "+numb2);
- if(numb2 >21)
- System.out.println("You lose!");
- if(numb ==21)
- System.out.println("You win!");
- if(numb2 <=22){
- System.out.print("Do you want another card? Yes [1], No [2]: ");
- choice = reader.readInt();
- while(choice == 1){
- choice++;
- card4 = generator.nextInt(12) + 1;
- numb3 = numb2 + card4;
- System.out.println("You got a " +card4);
- System.out.println("Your cards add up to "+numb3);
- if(numb3 >21)
- System.out.println("You lose!");
- if(numb ==21)
- System.out.println("You win!");
- }
- }
- }
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment