1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import java.util.*;
-
- public class NumberUtilities {
- public static String getRange(int stop) {
- String numRange = "";
- for (int i=0; i<stop; i++) {
- numRange += String.valueOf(i);
- }
- return numRange;
-
- }
-
- public static String getRange(int start, int stop) {
- String specNumRange = "";
- for (int i=start; i<stop; i++) {
- specNumRange += String.valueOf(i);
- }
- return specNumRange;
- }
-
- public static String getRange(int start, int stop, int step) {
- String stepNumRange = "";
- for (int i=start; i<stop; i+=step) {
- stepNumRange += String.valueOf(i);
- }
- return stepNumRange;
- }
-
- public static String getEvenNumbers(int start, int stop) {
- String evenNumRange = "";
- if (start%2 != 0) {
- start += 1;
- }
- for (int i=start; i<stop; i+=2) {
- evenNumRange += String.valueOf(i);
- }
- return evenNumRange;
- }
-
- public static String getOddNumbers(int start, int stop) {
- String oddNumRange = "";
- if (start%2 == 0) {
- start += 1;
- }
- for (int i=start; i<stop; i+=2) {
- oddNumRange += String.valueOf(i);
- }
- return oddNumRange;
- }
-
- public static String getSquareNumbers(int start, int stop) {
- String squareNumRange = "";
- for (int i=start; i<stop; i++) {
- squareNumRange += String.valueOf(i*i);
- }
- return squareNumRange;
- }
-
- public static String getExponentiations(int start, int stop, int exponent) {
- return getExponentiationsWithStep(start, stop, 1, exponent);
- }
-
- // getExponentiationsWithStep
- public static String getExponentiationsWithStep(int start, int stop, int step, int exponent) {
- String exNumRange = "";
- int exponentialNum = start;
- int result = 0;
- for (int i=start; i<=stop; i+=step) {
- result = (int)Math.pow(i,exponent);
- //System.out.println(result);
-
- exNumRange += String.valueOf(result);
- }
- return exNumRange;
- }
- }
|