NumberUtilities.java 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. public class NumberUtilities {
  2. public static String getRange(int stop) {
  3. String str= "";
  4. for (int i=0; i <=stop; i++){
  5. str +=i;}
  6. return str;
  7. }
  8. public static String getRange(int start, int stop) {
  9. String str ="";
  10. for (int i=start; i<= stop; i++){
  11. str+=i;
  12. }
  13. return str;
  14. }
  15. public static String getRange(int start, int stop, int step) {
  16. String str= "";
  17. for (int i= start; i<stop; i+=step ){
  18. str+=i;
  19. }
  20. return str;
  21. }
  22. public static String getEvenNumbers(int start, int stop) {
  23. String str = "";
  24. for (int i=start; i<stop; i+=2){
  25. str+=i;
  26. }
  27. return str;
  28. }
  29. public static String getOddNumbers(int start, int stop) {
  30. String str ="";
  31. for (int i=start; i<stop; i++){
  32. if(i%2!=0){
  33. str +=i;
  34. }
  35. }
  36. return str;
  37. }
  38. public static String getExponentiations(int start, int stop, int exponent) {
  39. String str = "";
  40. for (int i=start; i<stop; i+=exponent){
  41. str +=i;
  42. }
  43. return str;
  44. }
  45. }