12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
-
-
-
- public class NumberUtilities {
-
- public static String getRange(int stop) {
- return getRange(0, stop, 1);
- }
-
- public static String getRange(int start, int stop) {
- return getRange(start, stop, 1);
- }
-
-
- public static String getRange(int start, int stop, int step) {
- StringBuilder range = new StringBuilder();
-
- for (int i = start; i < stop; i += step) {
- range.append(i);
- }
-
- return range.toString();
- }
-
- public static String getEvenNumbers(int start, int stop) {
- //Start on an even number, step by 2
- start = (start % 2) == 1 ? start + 1 : start;
- return getRange(start, stop, 2);
- }
-
-
- public static String getOddNumbers(int start, int stop) {
- //Start on an odd number, step by 2
- start = (start % 2) == 0 ? start + 1 : start;
- return getRange(start, stop, 2);
- }
-
-
- public static String getExponentiations(int start, int stop, int exponent) {
- StringBuilder range = new StringBuilder();
-
- for (int i = start; i <= stop; i++) {
- range.append((int) Math.pow(i, exponent));
- }
-
- return range.toString();
- }
- }
|