Results 1 to 2 of 2
  1. #1
    PPhillips is offline Member
    Join Date
    Apr 2013
    Posts
    3
    Rep Power
    0

    Default 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;
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,784
    Blog Entries
    7
    Rep Power
    21

    Default Re: 100 Bottles of Beer issue

    One line of your version of that beautiful song runs like this:
    Java 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
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Help improving "bottles of beer on the wall" code
    By Palindrome5 in forum New To Java
    Replies: 5
    Last Post: 11-02-2012, 04:33 AM
  2. Replies: 8
    Last Post: 09-26-2012, 11:56 AM
  3. 10 green bottles
    By Dave013 in forum New To Java
    Replies: 2
    Last Post: 10-25-2011, 07:41 PM
  4. 'Bottles of Beer' project
    By s4rd59 in forum New To Java
    Replies: 2
    Last Post: 02-14-2010, 04:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •