14页习题BeerSong
自己稍微调整了下代码,加了一个换行,看起来段落更明显些。
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("Take one down.");
System.out.println("Pass it arount.");
beerNum = beerNum - 1;
if (beerNum > 0) {
System.out.println(beerNum + " " + word + " of beer on the wall" + "\n");
} else {
System.out.println("No more bottles of beer on the wall.");
}//else end
}//while end
}//main end
}//class end
20页习题排排看
class Shuffle1 {
public static void main(String [] args) {
int x = 3;
while (x > 0) {
if (x > 2) {
System.out.print("a");
}
x = x - 1;
System.out.print("-");
if (x == 2) {
System.out.print("b c");
}
x = x - 1;
System.out.print("-");
if (x == 1) {
System.out.print("d");
x = x - 1;
}
}
}
}