hello I am doing this excercise from my book and my code keeps ending up in a never ending loop and I can not figure out why.
I know the right answer to the assignment, but I was wondering if my way has a possibility to work. thank you!
----Exercise 4.3. The first verse of the song “99 Bottles of Beer” is:
99 bottles of beer on the wall, 99 bottles of beer, ya’ take one
down, ya’ pass it around, 98 bottles of beer on the wall.
Subsequent verses are identical except that the number of bottles gets smaller
by one in each verse, until the last verse:
No bottles of beer on the wall, no bottles of beer, ya’ can’t take
one down, ya’ can’t pass it around, ’cause there are no more
bottles of beer on the wall!
And then the song(finally) ends.
Write a program that prints the entire lyrics of “99 Bottles of Beer.” Your
program should include a recursive method that does the hard part, but you
might want to write additional methods to separate the major functions of
the program.
As you develop your code, test it with a small number of verses, like “3
Bottles of Beer.”
The purpose of this exercise is to take a problem and break it into smaller
problems, and to solve the smaller problems by writing simple methods.--------
public class BeersOnTheWall { //Print statement for countdown public static void beersOnWall(int OGbeers) { System.out.println(OGbeers+" bottles of beer on the wall,"); System.out.println(OGbeers+ " bottles of beer, ya' take one down pass it around, "+ (OGbeers-1) +" bottles of beer." ); beersOnWall(OGbeers-1); } //print statement for End of loop public static void noMoreBeers() { System.out.println("No bottles of beer on the wall, no bottles of beer, ya’ can’t take\r\n" + "one down, ya’ can’t pass it around, ’cause there are no more\r\n" + "bottles of beer on the wall!"); } //If statement begins here public static void song(int OGbeers) { if (OGbeers > 0){ beersOnWall(OGbeers); } else { noMoreBeers(); } } //Main initilaztion public static void main(String[] args) { song(3);