Workbook 5.4
From the Java Bootcamp Resources
, launch Workbook 5.4
.
99 bottles of beer on the wall.
A song as old as time itself.
Task 1 - Write a function
1. Function name:
/** * Function name -- sing. <------ * @param i (int) * * * Inside the function: * 1. print: * <i> bottles of beer on the wall, <i> bottles of beer! * take one down, pass it around <i-1>, bottles of beer on the wall! */
2. Parameters:
/** * Function name -- sing. * @param i (int) <------- * * * Inside the function: * 1. print: * <i> bottles of beer on the wall, <i> bottles of beer! * take one down, pass it around <i-1>, bottles of beer on the wall! */
3. Return value: void
.
4. Inside the function, add the following logic:
/** * Function name -- sing. * @param i (int) * * * Inside the function: <-------- * 1. print: * <i> bottles of beer on the wall, <i> bottles of beer! * take one down, pass it around <i-1>, bottles of beer on the wall! */
The first line is some number. The second line is one less the number.
58 bottles of beer on the wall, 58 bottles of beer.
take one down, pass it around, 57 bottles of beer on the wall!.
Task 2 - Write a loop
Make a for
loop that:
-
starts from
i
= 99. -
finishes at
i
= 1. -
loops down in steps of 1.
Call the function during each run. Your final output should start from 99 bottles of beer on the wall.
And end at 0 bottles of beers.
If you get this output, fix your condition.
Visualizing the Runtime
After you solve this workbook, I still recommend watching the video solution on Udemy.
It will show you how to visualize the runtime using Visual Studio Code.