在书上遇到一个例子,想试运行可是不成功。下面是代码:
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+""+word+"of beer.");
} else { System.out.println("No more bottles of beer on the wall");
} //end else
} // end while loop
} // end main method
} // end class我编译这个文件,然后得到:
beersong.java:6:需要‘;’
while (beerNum>0) {
^
1 错误我想后面应该不用加啊,书上都没有。然后我试着加了后,出现:
beersong.java:6 找不到符号
符号: 方法While(boolean)
位置:类 BeerSong
While (beerNum>0);{
^
1 错误加了又错,不加又错。SIGH。。为什么啊,请牛人指教!谢谢
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+""+word+"of beer.");
} else { System.out.println("No more bottles of beer on the wall");
} //end else
} // end while loop
} // end main method
} // end class我编译这个文件,然后得到:
beersong.java:6:需要‘;’
while (beerNum>0) {
^
1 错误我想后面应该不用加啊,书上都没有。然后我试着加了后,出现:
beersong.java:6 找不到符号
符号: 方法While(boolean)
位置:类 BeerSong
While (beerNum>0);{
^
1 错误加了又错,不加又错。SIGH。。为什么啊,请牛人指教!谢谢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货