forked from Zipcoder/BlueJ.NumbersTrianglesTables
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberUtilities.java
More file actions
54 lines (46 loc) · 1.43 KB
/
NumberUtilities.java
File metadata and controls
54 lines (46 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
public class NumberUtilities {
public static String getRange(int stop) {
StringBuilder sb = new StringBuilder();
for(int i = 0; i < stop;i++){
sb.append(i);
}
return sb.toString();
}
public static String getRange(int start, int stop) {
StringBuilder sb = new StringBuilder();
for(int i = start; i < stop;i++){
sb.append(i);
}
return sb.toString();
}
public static String getRange(int start, int stop, int step) {
StringBuilder sb = new StringBuilder();
for(int i = start; i < stop;i+=step){
sb.append(i);
}
return sb.toString();
}
public static String getEvenNumbers(int start, int stop) {
StringBuilder sb = new StringBuilder();
for(int i = start; i < stop;i++){
if(i % 2 == 0)
sb.append(i);
}
return sb.toString();
}
public static String getOddNumbers(int start, int stop) {
StringBuilder sb = new StringBuilder();
for(int i = start; i < stop;i++){
if(i % 2 == 1)
sb.append(i);
}
return sb.toString();
}
public static String getExponentiations(int start, int stop, int exponent) {
StringBuilder sb = new StringBuilder();
for(int i = start; i <= stop;i++){
sb.append((int)Math.pow(i,exponent));
}
return sb.toString();
}
}