-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeer.java
More file actions
44 lines (39 loc) · 1.39 KB
/
Beer.java
File metadata and controls
44 lines (39 loc) · 1.39 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
39
40
41
42
43
44
//Exercise 9.1
/*99 bottles of beer on the wall,
99 bottles of beer,
ya' take one down, ya' pass it around,
98 bottles of beer on the wall.
...
No bottles of beer on the wall,
no bottles of beer,
ya' can’t take one down, ya' can’t pass it around,
'cause there are no more bottles of beer on the wall!*/
import java.util.Scanner;
import java.util.Arrays;
class Beer {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the number you want to start with:");
int start = in.nextInt();
lyrics(start);
}
public static void lyrics(int n) {
for (int i = n; i >= 0; i--) {
if (i == 0) {
System.out.println("No bottles of beer on the wall,");
System.out.println("no bottles of beer,");
System.out.println("ya' can't take one down, ya' can't pass it around");
System.out.println("'cause there are no more bottles of beer on the wall!");
} else {
part(i);
}
}
}
public static void part(int number) {
System.out.println(number + " bottles of beer on the wall,");
System.out.println(number + " bottles of beer,");
System.out.println("ya' take one down, ya' pass it around,");
System.out.println((number - 1) + " bottles of beer on the wall.");
System.out.println();
}
}