《head first java》书中一道数啤酒瓶童谣的程序,求解释
最近在自学java,买了本《headfirstjava》,其中有一条关于数啤酒瓶童谣的程序,编译了可以运行,可是不知到程序意义,很难理解,求高手解答,谢谢!=======...
最近在自学java,买了本《head first java》,其中有一条关于数啤酒瓶童谣的程序,编译了可以运行,可是不知到程序意义,很难理解,求高手解答,谢谢!
=================================================================
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 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 + " " + worf + " of beer on the wall");
} else{
System.out.println("no more bottles of beer on the wall");
}
}
}
} 展开
=================================================================
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 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 + " " + worf + " of beer on the wall");
} else{
System.out.println("no more bottles of beer on the wall");
}
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询