Skip to content

Commit eb6e746

Browse files
authored
Create NinetyNineBottles.java
1 parent bcc8430 commit eb6e746

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

NinetyNineBottles.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.zetcode;
2+
3+
public class NinetyNineBottles {
4+
5+
6+
public static void main(String[] args) {
7+
8+
// 99 bottles of beer on the wall, 99 bottles of beer.
9+
// Take one down, pass it around, 98 bottles of beer on the wall
10+
11+
int nOfbottles = 99;
12+
13+
for (int i = nOfbottles; i >= 1; i--) {
14+
15+
if (i == 1) {
16+
17+
System.out.printf("%d bottle of beer on the wall, %d bottle of beer.%n", i, i);
18+
System.out.printf("Take one down, pass it around, %d bottle of beer on the wall.%n", i - 1);
19+
System.out.println();
20+
21+
} else {
22+
23+
System.out.printf("%d bottles of beer on the wall, %d bottles of beer.%n", i, i);
24+
System.out.printf("Take one down, pass it around, %d bottles of beer on the wall.%n", i - 1);
25+
System.out.println();
26+
}
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)