Java Bootcamp – Workbooks and Challenges
)}

Workbook 5.4

From the Java Bootcamp Resources, launch Workbook 5.4.

4.png

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.

4.png

It will show you how to visualize the runtime using Visual Studio Code.


Associated Course: The Complete Java Development Bootcamp
Related Course: The Complete Spring Boot Development Bootcamp – Become a Java Web Developer

Feedback Summary
4.7
43 students
5

91%
4

2%
3

0%
2

0%
1

7%
Written Reviews
There are no written reviews yet.