-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
164 lines (123 loc) · 7.4 KB
/
Main.java
File metadata and controls
164 lines (123 loc) · 7.4 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
public class Main {
public static void main(String[] args){
count22NoOverlapResults();
count22OverlapResults();
factorsOf10Results();
balancedParensResults();
//reverseArrayResults();
}
static void count22NoOverlapResults(){
Recursion test = new Recursion();
String noOverlap1 = "22abc22";
String output1 = "Test of count22NoOverlap method.\n" +
"Searching for \"22\" in string " + noOverlap1 + ".\n" +
"Found " + test.count22NoOverlap(noOverlap1) + " non-overlapping occurrences of \"22\".\n\n";
String noOverlap2 = "abc22x22x22";
String output2 = "Test of count22NoOverlap method.\n" +
"Searching for \"22\" in string " + noOverlap2 + ".\n" +
"Found " + test.count22NoOverlap(noOverlap2) + " non-overlapping occurrences of \"22\".\n\n";
String noOverlap3 = "222";
String output3 = "Test of count22NoOverlap method.\n" +
"Searching for \"22\" in string " + noOverlap3 + ".\n" +
"Found " + test.count22NoOverlap(noOverlap3) + " non-overlapping occurrences of \"22\".\n\n";
System.out.print(output1 + output2 + output3);
System.out.print("\n\n\n");
}
static void count22OverlapResults(){
Recursion test = new Recursion();
String overlap1 = "22abc22";
String output1 = "Test of count22Overlap method.\n" +
"Searching for \"22\" in string " + overlap1 + ".\n" +
"Found " + test.count22Overlap(overlap1) + " non-overlapping and overlapping occurrences of \"22\".\n\n";
String overlap2 = "abc22x22x22";
String output2 = "Test of count22Overlap method.\n" +
"Searching for \"22\" in string " + overlap2 + ".\n" +
"Found " + test.count22Overlap(overlap2) + " non-overlapping and overlapping occurrences of \"22\".\n\n";
String overlap3 = "222"; System.out.println(test.count22Overlap(overlap3));
String output3 = "Test of count22Overlap method.\n" +
"Searching for \"22\" in string " + overlap3 + ".\n" +
"Found " + test.count22Overlap(overlap3) + " non-overlapping and overlapping occurrences of \"22\".\n\n";
String overlap4 = "abc222222";
String output4 = "Test of count22Overlap method.\n" +
"Searching for \"22\" in string " + overlap4 + ".\n" +
"Found " + test.count22Overlap(overlap4) + " non-overlapping and overlapping occurrences of \"22\".\n\n";
System.out.print(output1 + output2 + output3 + output4);
System.out.print("\n\n\n");
}
static void factorsOf10Results(){
Recursion test = new Recursion();
int[] intArray1 = new int[]{ 1, 10, 20 };
String intArrayString1 = "";
for(int i = 0; i < intArray1.length; i++)
intArrayString1 += intArray1[i] + " ";
String output1 = "Test of factorsOf10 method.\n" +
"Searching for consecutive factors of 10 in array { " + intArrayString1 + "}.\n" +
"Found " + test.factorsOf10(intArray1, 0) + " consecutive factors of 10.\n\n";
int[] intArray2 = new int[]{ 100, 10, 20, 200 };
String intArrayString2 = "";
for(int i = 0; i < intArray2.length; i++)
intArrayString2 += intArray2[i] + " ";
String output2 = "Test of factorsOf10 method.\n" +
"Searching for consecutive factors of 10 in array { " + intArrayString2 + "}.\n" +
"Found " + test.factorsOf10(intArray2, 0) + " consecutive factors of 10.\n\n";
int[] intArray3 = new int[]{ 1000, 100, 10, 1, 10 };
String intArrayString3 = "";
for(int i = 0; i < intArray3.length; i++)
intArrayString3 += intArray3[i] + " ";
String output3 = "Test of factorsOf10 method.\n" +
"Searching for consecutive factors of 10 in array { " + intArrayString3 + "}.\n" +
"Found " + test.factorsOf10(intArray3, 0) + " consecutive factors of 10.\n\n";
int[] intArray4 = new int[]{ 10, 20, 33, 340 };
String intArrayString4 = "";
for(int i = 0; i < intArray4.length; i++)
intArrayString4 += intArray4[i] + " ";
String output4 = "Test of factorsOf10 method.\n" +
"Searching for consecutive factors of 10 in array { " + intArrayString4 + "}.\n" +
"Found " + test.factorsOf10(intArray4, 0) + " consecutive factors of 10.\n\n";
System.out.print(output1 + output2 + output3 + output4);
System.out.print("\n\n\n");
}
static void balancedParensResults(){
Recursion test = new Recursion();
ArrayStack stack = new ArrayStack();
String balParenString1 = "(a+b) * c";
String output1 = "Test of balancedParens method.\n" +
"Testing if parentheses are balanced in string " + balParenString1 + ".\n" +
"Parentheses are balanced: " + test.balancedParens(balParenString1, stack) + ".\n\n";
String balParenString2 = "c";
String output2 = "Test of balancedParens method.\n" +
"Testing if parentheses are balanced in string " + balParenString2 + ".\n" +
"Parentheses are balanced: " + test.balancedParens(balParenString2, stack) + ".\n\n";
String balParenString3 = "((a+b) * c)";
String output3 = "Test of balancedParens method.\n" +
"Testing if parentheses are balanced in string " + balParenString3 + ".\n" +
"Parentheses are balanced: " + test.balancedParens(balParenString3, stack) + ".\n\n";
String balParenString4 = "(a+b) * c)";
String output4 = "Test of balancedParens method.\n" +
"Testing if parentheses are balanced in string " + balParenString4 + ".\n" +
"Parentheses are balanced: " + test.balancedParens(balParenString4, stack) + ".\n\n";
String balParenString5 = "(a+b * c";
String output5 = "Test of balancedParens method.\n" +
"Testing if parentheses are balanced in string " + balParenString5 + ".\n" +
"Parentheses are balanced: " + test.balancedParens(balParenString5, stack) + ".\n\n";
System.out.print(output1 + output2 + output3 + output4 + output5);
System.out.print("\n\n\n");
}
static void reverseArrayResults(){
Recursion test = new Recursion();
Object[] objects = new Object[]{ "A", "B", "C", "D", "E"};
int index1 = 0;
int index2 = objects.length - 1;
String arrayString = "";
for(int i = 0; i < objects.length; i++)
arrayString += objects[i] + " ";
String output1 = "Test of reverseArray method.\n";
String output2 = "Original array is { " + arrayString + "}.\n";
String output3 = "Reverse array is { ";
String output4 = "}.\n\n";
System.out.print(output1 + output2 + output3);
test.TESTreverseArray(objects, index1, index2);
System.out.print(output4);
System.out.print("\n\n\n");
}
}