-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPartOne.java
More file actions
49 lines (44 loc) · 1.15 KB
/
Copy pathPartOne.java
File metadata and controls
49 lines (44 loc) · 1.15 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
45
46
47
48
49
/*
* PartOne.java
*
* Computer Science 111, Boston University
*
* A class that contains methods from Part I of PS 7.
*/
public class PartOne {
public static void printPattern(int m, int n) {
if (m == n) {
return;
}
if (m < n) {
System.out.print("(");
printPattern(m + 1, n);
System.out.print("\\"); /* prints a single backslash */
} else {
System.out.print("/");
printPattern(m, n + 1);
System.out.print(")");
}
}
public static void printReversePattern(int m, int n) {
if (m == n) {
return;
}
if (m < n) {
System.out.print("\\");
printReversePattern(m + 1, n);
System.out.print("(");
} else {
System.out.print(")");
printReversePattern(m, n + 1);
System.out.print("/");
}
}
public static int mystery(int a, int b) {
if (a * b == 0) {
return a;
} else {
return b + mystery(a - 1, b - 2);
}
}
}