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
94 lines (73 loc) · 2.64 KB
/
NumberUtilities.java
File metadata and controls
94 lines (73 loc) · 2.64 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import java.util.Arrays;
import java.util.ArrayList;
import java.lang.Math;
import java.lang.StringBuilder;
public class NumberUtilities {
/*
public static String getRange(int stop) {
String[] stringArr = new String[stop];
for (int i = 0; i < stop; i++){
stringArr[i] = Integer.toString(i);
}
String string = Arrays.toString(stringArr);
string = string.replaceAll(", ", "").replaceAll("\\[", "").replaceAll("\\]", "");
return string;
}
*/
public static String getRange(int start, int stop) {
String[] stringArr = new String[stop-start];
for (int i = 0; i < stringArr.length; i++){
stringArr[i] = Integer.toString(start + i);
}
String string = Arrays.toString(stringArr);
string = string.replaceAll(", ", "").replaceAll("\\[", "").replaceAll("\\]", "");
return string;
}
public static String getRange(int start, int stop, int step) {
ArrayList<Integer> arr = new ArrayList<>();
for (int i = start; i < stop; i += step) {
arr.add(i);
}
String string = arr.toString();
string = string.replaceAll(", ", "").replaceAll("\\[", "").replaceAll("\\]", "");
return string;
}
public static String getEvenNumbers(int start, int stop) {
ArrayList<Integer> arr = new ArrayList<>();
for (int i = start; i < stop; i++) {
if(i % 2 == 0) {
arr.add(i);
}
}
String string = arr.toString();
string = string.replaceAll(", ", "").replaceAll("\\[", "").replaceAll("\\]", "");
return string;
}
public static String getOddNumbers(int start, int stop) {
ArrayList<Integer> arr = new ArrayList<>();
for (int i = start; i < stop; i++) {
if(i % 2 != 0) {
arr.add(i);
}
}
String string = arr.toString();
string = string.replaceAll(", ", "").replaceAll("\\[", "").replaceAll("\\]", "");
return string;
}
public static String getExponentiations(int start, int stop, int exponent) {
ArrayList<Double> arr = new ArrayList<>();
for (int i = start; i <= stop; i++) {
arr.add(Math.pow(i, exponent));
}
String string = arr.toString();
string = string.replaceAll(", ", "").replaceAll("\\[", "").replaceAll("\\]", "").replaceAll(".0", "");
return string;
}
public static String getRange(int stop) {
String string = "";
for(int i = 0; i<stop; i++){
string = string+i;
}
return string;
}
}