Search This Blog

Friday, May 28, 2021

The Bear Song source code (java)

 The Bear Song


public class beer_song {
    public static void main(String[] args) {
        int beerNum = 10;
        String word =new String("bottles") ;
        while (beerNum > 0) {
            if (beerNum == 1) {
                word = "bottle"; // singular, as in ONE bottle.
            }
            System.out.println(beerNum + " " + word + " of beer on the wall");
            System.out.println(beerNum + " " + word + " of beer.");
            System.out.println("Take one down.");
            System.out.println("Pass it around.");
            System.out.println("\n");
            beerNum = beerNum - 1;
            } if (beerNum==0){
                System.out.println("No more bottles of beer on the wall");

            } // end else
        } // end while loop
    }