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