1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
-
-
-
- public class NumberUtilities {
-
- public static String getRange(int stop) {
- StringBuilder anw = new StringBuilder();
- for (int i=0; i<stop; i++){
-
- anw.append(i);
- }
-
-
-
- return anw.toString();
- }
-
- public static String getRange(int start, int stop) {
- StringBuilder anw = new StringBuilder();
- for (int i=start; i<stop;i++){
- anw.append(i);
- }
-
- return anw.toString();
- }
-
-
- public static String getRange(int start, int stop, int step) {
- StringBuilder anw = new StringBuilder();
- for (int i=start; i<stop; i=i+step){
- anw.append(i);
- }
- return anw.toString();
- }
-
- public static String getEvenNumbers(int start, int stop) {
- StringBuilder anw = new StringBuilder();
- if (!isEven(start)){
- start += 1;
- }
-
- for (int i=start;i<stop;i=i+2){
-
- anw.append(i);
- }
-
-
-
-
- return anw.toString();
- }
-
-
-
- public static String getOddNumbers(int start, int stop) {
- StringBuilder anw = new StringBuilder();
- if (isEven(start)){
- start = start+1;
- }
- for (int i=start;i<stop;i=i+2){
-
- anw.append(i);
- }
- return anw.toString();
- }
-
- public static boolean isEven(int num){
- return num % 2 == 0;
- }
-
- public static String getSquareNumbers(int start, int stop){
- StringBuilder anw = new StringBuilder();
- for (int i=start;i<=stop;i++){
- anw.append ((int) (Math.pow(i,2)));
-
- }
-
- return anw.toString();
- }
-
- public static String getExponentiations(int start, int stop, int exponent) {
- StringBuilder anw = new StringBuilder();
- for (int i=start; i<=stop; i++){
- anw.append((int)(Math.pow(i,exponent)));
-
-
- }
- return anw.toString();
- }
-
- }
|