123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- public class NumberUtilities {
-
- public static String getRange(int stop) {
- StringBuilder outcome = new StringBuilder();
- for(int i = 0; i < stop; i++) {
- outcome.append(i);
- }
- return outcome.toString();
- }
-
- public static String getRange(int start, int stop) {
- StringBuilder outcome = new StringBuilder();
- for(int i = start; i < stop; i++) {
- outcome.append(i);
- }
- return outcome.toString();
- }
-
- public static String getRange(int start, int stop, int step) {
- StringBuilder outcome = new StringBuilder();
- for(int i = start; i < stop; i+=step) {
- outcome.append(i);
- }
- return outcome.toString();
- }
-
- public static String getEvenNumbers(int start, int stop) {
- StringBuilder outcome = new StringBuilder();
- for(int i = start; i < stop; i++) {
- if (i % 2 == 0) {
- outcome.append(i);
- } else {
- continue;
- }
- }
- return outcome.toString();
- }
-
- public static String getOddNumbers(int start, int stop) {
- StringBuilder outcome = new StringBuilder();
- for(int i = start; i < stop; i++) {
- if (i % 2 != 0) {
- outcome.append(i);
- } else {
- continue;
- }
- }
- return outcome.toString();
- }
-
- public static String getExponentiations(int start, int stop, int exponent) {
- StringBuilder outcome = new StringBuilder();
- for (int i = start; i <= stop; i++) {
- int j = (int) Math.pow(i, exponent);
- outcome.append(j);
- }
- return outcome.toString();
- }
- }
|