Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- int pileA = 3;
- int pileB = 3;
- int pileC = 3;
- Scanner keyboard = new Scanner(System.in);
- String player1;
- String player2;
- System.out.println("Player 1, enter your name: ");
- player1 = keyboard.next();
- System.out.println("Player 2, enter your name: ");
- player2 = keyboard.next();
- String current = "";
- int remove;
- String pile = "";
- int remove2;
- String pile2 = "";
- do {
- System.out.println("\nA: " + pileA + " B: " + pileB + " C: " + pileC);
- System.out.println(player1 + ", choose a pile:");
- String choice = keyboard.next();
- System.out.print("\nHow many to remove from pile " + choice + ": ");
- remove = keyboard.nextInt();
- if (choice.equals("A")) {
- pileA = pileA - remove;
- } else if (choice.equals("B")) {
- pileB = pileB - remove;
- } else if (choice.equals("C")) {
- pileC = pileC - remove;
- }
- if ((pileA == 0) && (pileB == 0) && (pileC == 0)) {
- break;
- }
- System.out.println("\nA: " + pileA + " B: " + pileB + " C: " + pileC);
- System.out.println(player2 + ", choose a pile:");
- String choice2 = keyboard.next();
- System.out.print("\nHow many to remove from pile " + choice2 + ": ");
- remove2 = keyboard.nextInt();
- if (choice2.equals("A")) {
- pileA = pileA - remove;
- } else if (choice2.equals("B")) {
- pileB = pileB - remove;
- } else if (choice2.equals("C")) {
- pileC = pileC - remove;
- }
- }
- while (pileA > 0 || pileB > 0 || pileC > 0);
- if ((pileA == 0) && (pileB == 0) && (pileC == 0)) {
- if (current.equals(player1)) {
- System.out.println("\nA: " + pileA + " B: " + pileB + " C: " + pileC);
- System.out.println(player1 + ",there are no counters left, so you WIN!");
- } else {
- System.out.println("\nA: " + pileA + " B: " + pileB + " C: " + pileC);
- System.out.println(player2 + ",there are no counters left, so you WIN!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement