|
@@ -3,30 +3,64 @@
|
3
|
3
|
|
4
|
4
|
public class NumberUtilities {
|
5
|
5
|
|
6
|
|
- public static String getRange(int start) {
|
7
|
|
- return null;
|
|
6
|
+ public static String getRange(int stop) {
|
|
7
|
+ String ans = "";
|
|
8
|
+
|
|
9
|
+ for (int i = 0; i < stop; i++) {
|
|
10
|
+ ans = ans + i;
|
|
11
|
+ }
|
|
12
|
+ return ans;
|
8
|
13
|
}
|
9
|
14
|
|
10
|
15
|
public static String getRange(int start, int stop) {
|
11
|
|
- return null;
|
|
16
|
+ String ans = "";
|
|
17
|
+
|
|
18
|
+ for (int i = start; i < stop; i++) {
|
|
19
|
+ ans = ans + i;
|
|
20
|
+ }
|
|
21
|
+ return ans;
|
12
|
22
|
}
|
13
|
23
|
|
14
|
24
|
|
15
|
25
|
public static String getRange(int start, int stop, int step) {
|
16
|
|
- return null;
|
|
26
|
+ String ans = "";
|
|
27
|
+
|
|
28
|
+ for (int i = start; i < stop; i += step) {
|
|
29
|
+ ans = ans + i;
|
|
30
|
+ }
|
|
31
|
+ return ans;
|
17
|
32
|
}
|
18
|
33
|
|
19
|
34
|
public static String getEvenNumbers(int start, int stop) {
|
20
|
|
- return null;
|
|
35
|
+ String ans = "";
|
|
36
|
+
|
|
37
|
+ for (int i = start; i < stop; i++) {
|
|
38
|
+ if (i % 2 == 0) {
|
|
39
|
+ ans = ans + i;
|
|
40
|
+ }
|
|
41
|
+ }
|
|
42
|
+ return ans;
|
21
|
43
|
}
|
22
|
44
|
|
23
|
45
|
|
24
|
46
|
public static String getOddNumbers(int start, int stop) {
|
25
|
|
- return null;
|
|
47
|
+ String ans = "";
|
|
48
|
+
|
|
49
|
+ for (int i = start; i < stop; i++) {
|
|
50
|
+ if (i % 2 != 0) {
|
|
51
|
+ ans = ans + i;
|
|
52
|
+ }
|
|
53
|
+ }
|
|
54
|
+ return ans;
|
26
|
55
|
}
|
27
|
56
|
|
28
|
57
|
|
29
|
58
|
public static String getExponentiations(int start, int stop, int exponent) {
|
30
|
|
- return null;
|
|
59
|
+ String ans = "";
|
|
60
|
+
|
|
61
|
+ for (int i = start; i <= stop; i++) {
|
|
62
|
+ ans = ans + ((int)Math.pow(i, exponent));
|
|
63
|
+ }
|
|
64
|
+ return ans;
|
31
|
65
|
}
|
32
|
66
|
}
|