链接的问题:http://rosettacode.org/wiki/99_Bottles_of_Beer刚刚启动的Java,这是一个适合99瓶瓶装啤酒的适当解决方案吗?
我的代码:
import java.util.Scanner;
public class Application {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Please enter the number of bottles of beer on the wall: ");
int X = input.nextInt();
do {
if (X == 1) {
System.out.println(X + " bottle of beer on the wall");
System.out.println(X + " bottle of beer");
System.out.println("Take one down, pass it around");
System.out.println(X-- + " bottle of beer on the wall");
System.out.println();
} else {
System.out.println(X + " bottles of beer on the wall");
System.out.println(X + " bottles of beer");
System.out.println("Take one down, pass it around");
System.out.println(X-- + " bottles of beer on the wall");
System.out.println();
}
} while (X >= 0);
}
}
是否有这样做的更好的方法?在学校递归方面我已经感受到了一点点,但不知道如何在Java中实现它。有什么建议么?
那么你可以避免难以发现的副作用......''System.out.println(X-- +“瓶壁上的啤酒”);' –
我投票结束这个问题作为题外话,因为它属于http://codereview.stackexchange.com/ –