【java】數啤酒程序
阿新 • • 發佈:2019-02-09
ott round bottle 圖片 args ring around 分享圖片 system
public class BeerSong{ public static void main(String[] args){ int beerNum = 99; String word = "bottles"; while(beerNum > 0){ if(beerNum == 1){ word = "bottle"; } System.out.println(beerNum + " " + word + " of beer of 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("no more bottles of beer on the wall"); } } } }
在文本編輯器中輸入上述代碼,保存為BeerSong.java文件。
先把java文件編譯成可執行的class文件,然後執行。
執行結果(只截取了最後一部分):
【java】數啤酒程序