import java.util.Scanner; 

// plays the stick game between two players
public class StickGame { 
    
    public static void main(String[] args) { 
        int row,num;
        // initialize number of sticks in each row
        int r1 = 1, r2=2, r3=3, r4=4, r5=5;
        
        Scanner scan = new Scanner(System.in); 
        
        // use a boolean to toggle between players
        boolean player = true;
        // and another boolean to check if the game is over
        boolean over = false;

        // ask for user input until the game is over
        while(!over) {
            // print board
            int i;
            String lines="1: ";
            for (i=0;i<r1;i++) 
                lines += "|";
            System.out.println(lines);
            lines="2: ";
            for (i=0;i<r2;i++) 
                lines += "|";
            System.out.println(lines);
            lines="3: ";
            for (i=0;i<r3;i++) 
                lines += "|";
            System.out.println(lines);
            lines="4: ";
            for (i=0;i<r4;i++) 
                lines += "|";
            System.out.println(lines);
            lines="5: ";
            for (i=0;i<r5;i++) 
                lines += "|";
            System.out.println(lines);
            
            // select appropriate player
            String playerName = (player) ? "Player A" : "Player B";
            // let user move
            System.out.println(playerName+"'s move");
            System.out.print("Enter the row: "); 
            row = scan.nextInt(); 
            System.out.print("Enter the number: "); 
            num = scan.nextInt();
            switch(row) {
            case 1:
                r1 -= num;
                break;
            case 2:
                r2 -= num;
                break;
            case 3:
                r3 -= num;
                break;
            case 4:
                r4 -= num;
                break;
            case 5:
                r5 -= num;
                break;
            }
            // check if the game is over
            if (r1==0 && r2==0 && r3==0 && r4==0 && r5==0) {
                System.out.println(playerName+" won!");
                over=true;
            } else {
                // change players
                player = !player;
            }
        } 
    } 
} 
