Cruel 103 Share 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..."); } } } } Link to comment Share on other sites More sharing options...
Hashtag 8699 Share Posted May 25, 2015 Haha this is nice! Well done mate Link to comment Share on other sites More sharing options...
Cruel 103 Author Share 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. Link to comment Share on other sites More sharing options...
NVS 14 Share 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. Link to comment Share on other sites More sharing options...
Stormscythe 263 Share Posted May 25, 2015 Never nice progress buddy! Happy to see you improve :-) Link to comment Share on other sites More sharing options...
Novak 35 Share Posted May 25, 2015 you could have made a for loop and made this like 2 lines, but this is good for a beginner Link to comment Share on other sites More sharing options...
Cruel 103 Author Share Posted May 25, 2015 Thanks for all the input guys Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.