-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeerSong.java
More file actions
38 lines (33 loc) · 1.04 KB
/
BeerSong.java
File metadata and controls
38 lines (33 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* To compile it from the Command Line:
* javac BeerSong.java
* To run it from the Command Line:
* java 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(beerNum + " " + word + " of beer.");
if (beerNum % 2 != 0){
beerNum -= 2;
System.out.println("Take two down.");
}
else {
System.out.println("Take one down.");
beerNum--;
}
System.out.println("Pass it around.") ;
if (beerNum > 0) {
System.out.println(beerNum + " " + word + " of beer on the wall");
} else {
System.out.println("No more bottles of beer on the wall.");
} // end else
} // end while loop
} // end main method
} // end class