NumberUtilities.java 1.4KB

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