Java Bootcamp – Workbooks and Challenges
)}

Workbook 5.4

From Java Bootcamp Resources -> Module 1 -> 5. Loops, open 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.

Good Luck!


Feedback Summary
4.8
38 students
5

92%
4

3%
3

0%
2

0%
1

5%
Written Reviews
There are no written reviews yet.