Cruel 103 Posted May 25, 2015 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..."); } } } }
Cruel 103 Author Posted May 25, 2015 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.
NVS 14 Posted May 25, 2015 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.
Novak 35 Posted May 25, 2015 you could have made a for loop and made this like 2 lines, but this is good for a beginner
Recommended Posts
Archived
This topic is now archived and is closed to further replies.