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