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