Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Learning Java Basic Integer and String Experiment


    Cruel

    Recommended Posts

    Posted

    From some reading I was able to complete this small little script that would run and do the "beers on the wall" song. I thought I'd share just for fun :) I'm getting the hang of the basics!

    public class BeerSong {
    	public static void main (String[] args) {
    		
    		int beerNum = 99 ;
    		
    		String word = " bottles ";
    		
    		while (beerNum > 0) {
    			
    			if (beerNum == 1) {
    				word = " bottle "; //A SINGULAR bottle.
    			}
    			
    			System.out.println(beerNum + "" + word + "of beer on the wall" );
    			System.out.println(beerNum + "" + word + "of beer" );
    			System.out.println("Take one down");
    			System.out.println("Pass it around");
    			beerNum = beerNum - 1;
    			
    			if (beerNum > 0) {
    				System.out.println(beerNum + "" + word + "of beer on the wall" );
    			} else {
    				System.out.println("No more bottles of beer on the wall...");
    				System.out.println("The dwarfs are gonna be pissed about this...");
    			}
    		}
    	}
    }
    
    Posted

    Haha this is nice! Well done mate :)

     

    Such a little noob piece of code, but I'll tell you what... I'm having so much fun with this lol.

    Posted

    I think there's a small problem with your counting down logic. 

    if (beerNum == 1) {
        word = " bottle "; //A SINGULAR bottle.
    }
    

    should come after your beerNum = beerNum - 1;

     

    You can also remove 

    if (beerNum > 0) {
       ...
    }
    

    from your while block and put the else block code after the while loop.

     

    Nice start, keep up the learning.

    Posted

    you could have made a for loop and made this like 2 lines, but this is good for a beginner :)

    Posted

    Thanks for all the input guys :)

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.