123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
-
- public class NumberUtilities {
-
- public static String getRange(int start) {
- String range = "";
- for (int i = 0; i < start; i++) {
- range += i;
- }
- return range;
- }
-
- public static String getRange(int start, int stop) {
-
- String range = "";
- for (int i = start; i < stop; i++) {
- range += i;
- }
-
- return range;
- }
-
- public static String getRange(int start, int stop, int step) {
- String range = "";
-
- for (int i = start; i < stop; i += step) {
- range += i;
- }
- return range;
- }
-
- public static String getEvenNumbers(int start, int stop) {
- String evenNumbers = "";
-
- if(start % 2 == 0) {
- for(int i = start; i < stop; i += 2){
- evenNumbers += i;
- }
- }else if(start % 2 == 1){
- for(int i = start + 1; i < stop; i += 2){
- evenNumbers += i;
- }
- }
- return evenNumbers;
- }
-
-
- public static String getOddNumbers(int start, int stop) {
-
- String oddNumbers = "";
-
- if (start % 2 == 1){
- for(int i = start; i < stop; i += 2) {
- oddNumbers += i;
- }
- } else if (start % 2 == 0){
- for(int i = start + 1; i < stop; i += 2){
- oddNumbers += i;
- }
- }
- return oddNumbers;
- }
-
-
- public static String getExponentiations(int start, int stop, int exponent) {
-
- String expon = "";
-
- if (exponent == 2){
- for (int i = start; i < stop + 1; i++){
- expon += i * i;
- }
- } else if (exponent == 3){
- for (int i = start; i < stop + 1; i++){
-
- expon += i * i * i;
- }
- }
- return expon;
- }
- }
|