Advertisement
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 p1 = 3;
- int p2 = 3;
- int p3 = 3;
- String pile = " ";
- int remove;
- while(p1 > 0 || p2 > 0 || p3 > 0){
- System.out.println("A. " + p1 + " B. " + p2 + " C. " + p3);
- System.out.print("Choose a pile: ");
- pile = keyboard.next();
- System.out.print("How many to remove from pile " + pile + ": ");
- remove = keyboard.nextInt();
- if(pile.equals("A")){
- p1 = p1 - remove;
- }else if(pile.equals("B")){
- p2 = p2 - remove;
- }else if(pile.equals("C")){
- p3 = p3 - remove;
- }if(p1 == 0 && p2 == 0 && p3 == 0)
- {
- System.out.println("A. " + p1 + " B. " + p2 + " C. " + p3);
- System.out.print("All piles are empty. Good job!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement