Download this file
23 lines (21 with data), 636 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 | public class BeerGame {
public static void main(String[] args) {
String word = "bottles";
int beerNum = 3;
while (beerNum > 0) {
System.out.print(beerNum + " " + word + " of beer on the wall, ");
System.out.println(beerNum + " " + word + " of beer.");
System.out.print("Take one down! ");
System.out.print("Pass it around. ");
beerNum = beerNum - 1;
if (beerNum > 0) {
if (beerNum == 1) {
word = "bottle"; //singular
}
System.out.println(beerNum + " " + word + " of beer on the wall");
} else {
System.out.println("No more beers on the wall!");
}
}
}
}
|
×
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.