# 100 Bottles of Beer issue

• 05-03-2013, 07:34 PM
PPhillips
100 Bottles of Beer issue
I am required to design a program that prints the first few verses of the song "100 bottles of beer". The program should display the amount of verses of the song the user inputs, starting with "100 bottles of beer on the wall 100 bottles of beer, take one down pass it around 99 bottles of beer on the wall."
For example: if the user input 3, the program should read
"100 bottles of beer on the wall 100 bottles of beer, take one down pass it around 99 bottles of beer on the wall.
99 bottles of beer on the wall 100 bottles of beer, take one down pass it around 98 bottles of beer on the wall.
98 bottles of beer on the wall 100 bottles of beer, take one down pass it around 97 bottles of beer on the wall."
My code so far is prett rough. The issue is most likely my math throughout the code. thanks

import java.util.Scanner;

public class Beer {
public static void main(String[] args) {

Scanner scan = new Scanner(System.in);
int hunna = 100, user, total, minus = 0, it;
System.out.println("How many verses?: ");
user = scan.nextInt();
total = (int)(hunna - user);
minus = total - 1;
System.out.println("100 bottles of beer on the wall 100 bottles of beer, take one down pass it around 99 bottles of beer on the wall.");
it = total + minus;
while (it >= total){
it = total + minus;
System.out.println(it +" bottles of beer on the wall " + it + " bottles of beer, take one down pass it around " + minus + " bottles of beer on the wall.");
it = it -1;
}
• 05-03-2013, 07:46 PM
JosAH
Re: 100 Bottles of Beer issue
One line of your version of that beautiful song runs like this:
Code:

`n XXX 100 XXX (n-1) XXX`
where the 'XXX's represent the beautiful lyrics of that beautiful song and 'n' represents any number in the range 100 ... 1; create a loop for the different values for 'n' and voila.

kind regards,

Jos