NumberUtilities.java 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import java.lang.*;
  2. public class NumberUtilities {
  3. public static String getRange(int stop) {
  4. String str = "";
  5. for(int i = 0; i < stop; i++)
  6. {
  7. str = str.concat(Integer.toString(i));
  8. }
  9. return str;
  10. }
  11. public static String getRange(int start, int stop) {
  12. String str = "";
  13. for(int i = start; i < stop; i++)
  14. {
  15. str = str.concat(Integer.toString(i));
  16. }
  17. return str;
  18. }
  19. public static String getRange(int start, int stop, int step) {
  20. String str = "";
  21. for(int i = start; i < stop; i += step)
  22. {
  23. str = str.concat(Integer.toString(i));
  24. }
  25. return str;
  26. }
  27. public static String getEvenNumbers(int start, int stop) {
  28. int startEven = (start % 2 != 0) ? start + 1 : start;
  29. String str = "";
  30. for(int i = startEven; i < stop; i += 2)
  31. {
  32. str = str.concat(Integer.toString(i));
  33. }
  34. return str;
  35. }
  36. public static String getOddNumbers(int start, int stop) {
  37. int startOdd = (start % 2 == 0) ? start + 1 : start;
  38. String str = "";
  39. for(int i = startOdd; i < stop; i += 2)
  40. {
  41. str = str.concat(Integer.toString(i));
  42. }
  43. return str;
  44. }
  45. public static String getExponentiations(int start, int stop, int exponent) {
  46. String str = "";
  47. double exponentD = exponent;
  48. int tempInt;
  49. for(double i = start; i <= stop; i++)
  50. {
  51. tempInt = (int)(Math.pow(i, exponentD));
  52. str = str.concat(Integer.toString(tempInt));
  53. }
  54. return str;
  55. }
  56. }