Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner keyboard = new Scanner(System.in);
- int pileA = 3;
- int pileB = 3;
- int pileC = 3;
- String player1;
- String player2;
- String currentPlayer = "";
- String pile = " ";
- int remove;
- System.out.println("Player 1, enter your name: ");
- player1 = keyboard.next();
- System.out.println("Player 2, enter your name: ");
- player2 = keyboard.next();
- if (pileA > 0 || pileB > 0 || pileC > 0)
- do {
- System.out.print(" A:" + pileA);
- System.out.print(" B:" + pileB);
- System.out.print(" C:" + pileC);
- System.out.println("\n" + player1 + ", Choose a pile: ");
- pile = keyboard.next();
- System.out.println("How many to remove from pile " + pile + ": ");
- remove = keyboard.nextInt();
- if (pile.equals("A")) {
- pileA = pileA - remove;
- } else if (pile.equals("B")) {
- pileB = pileB - remove;
- } else if (pile.equals("C")) {
- pileC = pileC - remove;
- }
- System.out.print("A:" + pileA);
- System.out.print(" B:" + pileB);
- System.out.print(" C:" + pileC);
- System.out.println("\n" + player2 + ", Choose a pile: ");
- pile = keyboard.next();
- System.out.println("How many to remove from pile " + pile + ": ");
- remove = keyboard.nextInt();
- if (pile.equals("A")) {
- pileA = pileA - remove;
- } else if (pile.equals("B")) {
- pileB = pileB - remove;
- } else if (pile.equals("C")) {
- pileC = pileC - remove;
- if (pileA + pileB + pileC == 0 && currentPlayer.equals(player1)) {
- System.out.println("A: " + pileA + " B: " + pileB + " C: " + pileC);
- System.out.println("All piles are empty, Good job! " + player1 );
- }else{
- System.out.println("A: " + pileA + " B: " + pileB + " C: " + pileC);
- System.out.println("All piles are empty, Good job! " + player2);
- }
- }
- } while (pileA > 0 || pileB > 0 || pileC > 0) ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment