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