1. 程式人生 > >【java】數啤酒程序

【java】數啤酒程序

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】數啤酒程序