123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. public class NumberUtilities {
  2. public static String getRange(int start) {
  3. String range = "";
  4. for (int i = 0; i < start; i++) {
  5. range += i;
  6. }
  7. return range;
  8. }
  9. public static String getRange(int start, int stop) {
  10. String range = "";
  11. for (int i = start; i < stop; i++) {
  12. range += i;
  13. }
  14. return range;
  15. }
  16. public static String getRange(int start, int stop, int step) {
  17. String range = "";
  18. for (int i = start; i < stop; i += step) {
  19. range += i;
  20. }
  21. return range;
  22. }
  23. public static String getEvenNumbers(int start, int stop) {
  24. String evenNumbers = "";
  25. if(start % 2 == 0) {
  26. for(int i = start; i < stop; i += 2){
  27. evenNumbers += i;
  28. }
  29. }else if(start % 2 == 1){
  30. for(int i = start + 1; i < stop; i += 2){
  31. evenNumbers += i;
  32. }
  33. }
  34. return evenNumbers;
  35. }
  36. public static String getOddNumbers(int start, int stop) {
  37. String oddNumbers = "";
  38. if (start % 2 == 1){
  39. for(int i = start; i < stop; i += 2) {
  40. oddNumbers += i;
  41. }
  42. } else if (start % 2 == 0){
  43. for(int i = start + 1; i < stop; i += 2){
  44. oddNumbers += i;
  45. }
  46. }
  47. return oddNumbers;
  48. }
  49. public static String getExponentiations(int start, int stop, int exponent) {
  50. String expon = "";
  51. if (exponent == 2){
  52. for (int i = start; i < stop + 1; i++){
  53. expon += i * i;
  54. }
  55. } else if (exponent == 3){
  56. for (int i = start; i < stop + 1; i++){
  57. expon += i * i * i;
  58. }
  59. }
  60. return expon;
  61. }
  62. }