我正在努力应对大学的Java,我不知道为什么。以前我做了一个C编程的学期,我发现这很容易,但我似乎无法绕过Java。我目前正处于Java编程的第四周,我正在尝试将瓶装啤酒歌曲程序编写为我的讲师标准,我不太明白他要求我做什么做。我能够以相当快的速度编写代码,但是我不太了解我的讲师指示。
public class BottlesOfBeer
{
public static void main(String[] args)
{
int beerNum = 99;
while (beerNum > 0)
{
System.out.println(beerNum + " bottles of beer on the wall " + beerNum + " bottles of beer. Take one down. Pass it around. " + (beerNum - 1)+ " bottles of beer on the wall.");
beerNum--;
}
System.out.println("No more bottles of beer on the wall");
}
讲师说明:
答案 0 :(得分:0)
你在路上。尝试类似:
public class BottlesOfBeer
{
int beerNum; // instance field
// Constructor: accept number of beer bottles
private BottlesOfBeer(int beerNum)
{
this.beerNum = beerNum; // Store in instance field
}
public static void main(String[] args)
{
// Assume first arg contains the number of bottles
BottlesOfBeer beer = new BottlesOfBeer(Integer.parseInt(args[0]));
beer.startDrinking();
}
public void startDrinking()
{
while (beerNum> 0)
{
System.out.println(beerNum + " bottles of beer on the wall " + beerNum + " bottles of beer. Take one down. Pass it around. " + (beerNum - 1) + " bottles of beer on the wall.");
beerNum--;
}
System.out.println("No more bottles of beer on the wall");
}
}