|
@@ -5,53 +5,34 @@ public class NumberUtilities {
|
5
|
5
|
|
6
|
6
|
public static String getEvenNumbers(int start, int stop) {
|
7
|
7
|
String evens = "";
|
8
|
|
- int count = start;
|
9
|
|
- if((count / 2) != 0) {
|
10
|
|
- count += 1;
|
11
|
|
- }
|
12
|
|
- for(int i = count; i < stop; i+=2) {
|
13
|
|
- evens = evens + i;
|
14
|
|
- }
|
|
8
|
+ if(start%2 != 0) start += 1;
|
|
9
|
+ for(int i = start; i < stop; i+=2) evens += i;
|
15
|
10
|
return evens;
|
16
|
11
|
}
|
17
|
12
|
|
18
|
|
-
|
19
|
13
|
public static String getOddNumbers(int start, int stop) {
|
20
|
14
|
String odds = "";
|
21
|
|
- int count = start;
|
22
|
|
- if((count / 2) == 0) {
|
23
|
|
- count += 1;
|
24
|
|
- }
|
25
|
|
- for(int i = count; i < stop; i+=2) {
|
26
|
|
- odds += i;
|
27
|
|
- }
|
|
15
|
+ if(start %2 == 0) start += 1;
|
|
16
|
+ for(int i = start; i < stop; i+=2) odds += i;
|
28
|
17
|
return odds;
|
29
|
18
|
}
|
30
|
19
|
|
31
|
|
-
|
32
|
20
|
public static String getSquareNumbers(int start, int stop, int step) {
|
33
|
21
|
String square = "";
|
34
|
|
- for(int i = start; i < stop; i+=step) {
|
35
|
|
- square += (i*i);
|
36
|
|
- }
|
|
22
|
+ for(int i = start; i < stop; i+=step) square += (i*i);
|
37
|
23
|
return square;
|
38
|
24
|
}
|
39
|
25
|
|
40
|
|
-
|
41
|
26
|
public static String getRange(int start, int stop, int step) {
|
42
|
27
|
String xEach = "";
|
43
|
|
- for(int i = start; i < stop; i+=step){
|
44
|
|
- xEach += i;
|
45
|
|
- }
|
|
28
|
+ for(int i = start; i < stop; i+=step) xEach += i;
|
46
|
29
|
return xEach;
|
47
|
30
|
}
|
48
|
31
|
|
49
|
|
-
|
50
|
32
|
public static String getExponentiations(int start, int stop, int step, int exponent) {
|
51
|
33
|
String expo = "";
|
52
|
34
|
for(int i = start; i< stop; i+=step){
|
53
|
|
- expo += (int)(Math.pow(i, exponent));
|
54
|
|
- }
|
|
35
|
+ expo += (int)(Math.pow(i, exponent)); }
|
55
|
36
|
return expo;
|
56
|
37
|
}
|
57
|
38
|
}
|