12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- import java.lang.StringBuilder;
-
-
- public class NumberUtilities {
-
- public static String getRange(int stop) {
-
- StringBuilder sb = new StringBuilder();
- //for each int between 0 and stop var append i
- 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 each in bw start and stop append i
- 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 each in bw start and stop append i at each interval step
- 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 each in bw start and stop append i if even
- 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 each in bw start and stop append i if odd
- for (int i = start; i < stop; i++) {
-
- if (i % 2 != 0) {
- sb.append(i);
- }
- }
- return sb.toString();
- }
-
-
- public static String getExponentiations(int start, int stop, int exponent) {
-
- StringBuilder sb = new StringBuilder();
- // for each in bw start and stop append i^exp
-
- for (int i = start; i <= stop; i++) {
- sb.append((int)Math.pow(i, exponent));
- }
- return sb.toString();
- }
- }
|