12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
-
- public class NumberUtilities {
- public static String getRange(int stop) {
- StringBuilder range = new StringBuilder();
-
- for(int i=0; i<stop; i++){
- range.append(i);
- }
-
- return range.toString();
- }
-
- public static String getRange(int start, int stop) {
- StringBuilder range = new StringBuilder();
-
- for(int i=start; i<stop; i++){
- range.append(i);
- }
-
- return range.toString();
- }
-
- 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) {
- StringBuilder range = new StringBuilder();
-
- if (start % 2 == 0){
- for(int i=start; i<stop; i += 2){
- range.append(i);
- }
- } else {
- for(int i=start+1; i<stop; i += 2){
- range.append(i);
- }
- }
-
- return range.toString();
- }
-
- public static String getOddNumbers(int start, int stop) {
- StringBuilder range = new StringBuilder();
-
- if (start % 2 == 0){
- for(int i=start+1; i<stop; i += 2){
- range.append(i);
- }
- } else {
- for(int i=start; i<stop; i += 2){
- range.append(i);
- }
- }
-
- return range.toString();
- }
-
- public static String getSquareNumbers(int start, int stop){
- StringBuilder range = new StringBuilder();
-
- for(int i=start; i<=stop; i ++){
- range.append(i*i);
- }
-
- return range.toString();
- }
-
- 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();
- }
- }
|