Advertisement
Blonk

Untitled

Dec 9th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args){
  5.  
  6.  
  7.         Scanner keyboard = new Scanner(System.in);
  8.         int p1 = 3;
  9.         int p2 = 3;
  10.         int p3 = 3;
  11.  
  12.         String pile = " ";
  13.         int remove;
  14.  
  15.         while(p1 > 0 || p2 > 0 || p3 > 0){
  16.             System.out.println("A. " + p1 + "   B. " + p2 + "   C. " + p3);
  17.             System.out.print("Choose a pile: ");
  18.             pile = keyboard.next();
  19.  
  20.             System.out.print("How many to remove from pile " + pile + ": ");
  21.             remove = keyboard.nextInt();
  22.  
  23.             if(pile.equals("A")){
  24.                 p1 = p1 - remove;
  25.             }else if(pile.equals("B")){
  26.                 p2 = p2 - remove;
  27.             }else if(pile.equals("C")){
  28.                 p3 = p3 - remove;
  29.             }if(p1 == 0 && p2 == 0 && p3 == 0)
  30.             {
  31.                 System.out.println("A. " + p1 + "   B. " + p2 + "   C. " + p3);
  32.                 System.out.print("All piles are empty. Good job!");
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement