NumberUtilities.java 1.8KB

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