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