forked from careercup/ctci
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion.java
More file actions
36 lines (32 loc) · 895 Bytes
/
Question.java
File metadata and controls
36 lines (32 loc) · 895 Bytes
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
package Question10_7;
public class Question {
public static String[] generateResults(int i) {
String[] results = {"resultA" + i, "resultB" + i, "resultC" + i};
return results;
}
public static void main(String[] args) {
Cache cache = new Cache();
for (int i = 0; i < 20; i++) {
String query = "query" + i;
cache.insertResults(query, generateResults(i));
if (i == 9 || i == 16 || i == 19) {
cache.getResults("query" + 2);
cache.getResults("query" + 6);
cache.getResults("query" + 9);
}
}
for (int i = 0; i < 30; i++) {
String query = "query" + i;
String[] results = cache.getResults(query);
System.out.print(query + ": ");
if (results == null) {
System.out.print("null");
} else {
for (String s : results) {
System.out.print(s + ", ");
}
}
System.out.println("");
}
}
}