Advertisement
CamiloCastilla

Untitled

Dec 14th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.48 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         int pileA = 3;
  9.         int pileB = 3;
  10.         int pileC = 3;
  11.  
  12.         Scanner keyboard = new Scanner(System.in);
  13.         String player1;
  14.         String player2;
  15.  
  16.         System.out.println("Player 1, enter your name: ");
  17.         player1 = keyboard.next();
  18.         System.out.println("Player 2, enter your name: ");
  19.         player2 = keyboard.next();
  20.         String current = "";
  21.         int remove;
  22.         String pile = "";
  23.         int remove2;
  24.         String pile2 = "";
  25.  
  26.  
  27.         do {
  28.             System.out.println("\nA:  " + pileA + "  B:  " + pileB + "  C:  " + pileC);
  29.             System.out.println(player1 + ",  choose a pile:");
  30.             String choice = keyboard.next();
  31.             System.out.print("\nHow many to remove from pile " + choice + ": ");
  32.             remove = keyboard.nextInt();
  33.             if (choice.equals("A")) {
  34.                 pileA = pileA - remove;
  35.             } else if (choice.equals("B")) {
  36.                 pileB = pileB - remove;
  37.             } else if (choice.equals("C")) {
  38.                 pileC = pileC - remove;
  39.             }
  40.  
  41.             if ((pileA == 0) && (pileB == 0) && (pileC == 0)) {
  42.                 break;
  43.             }
  44.  
  45.             System.out.println("\nA:  " + pileA + "  B:  " + pileB + "  C:  " + pileC);
  46.             System.out.println(player2 + ",  choose a pile:");
  47.             String choice2 = keyboard.next();
  48.             System.out.print("\nHow many to remove from pile " + choice2 + ": ");
  49.             remove2 = keyboard.nextInt();
  50.  
  51.             if (choice2.equals("A")) {
  52.                 pileA = pileA - remove;
  53.             } else if (choice2.equals("B")) {
  54.                 pileB = pileB - remove;
  55.             } else if (choice2.equals("C")) {
  56.                 pileC = pileC - remove;
  57.             }
  58.  
  59.         }
  60.         while (pileA > 0 || pileB > 0 || pileC > 0);
  61.  
  62.         if ((pileA == 0) && (pileB == 0) && (pileC == 0)) {
  63.             if (current.equals(player1)) {
  64.                 System.out.println("\nA:  " + pileA + "  B:  " + pileB + "  C:  " + pileC);
  65.                 System.out.println(player1 + ",there are no counters left, so you WIN!");
  66.             } else {
  67.                 System.out.println("\nA:  " + pileA + "  B:  " + pileB + "  C:  " + pileC);
  68.                 System.out.println(player2 + ",there are no counters left, so you WIN!");
  69.             }
  70.  
  71.         }
  72.     }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement