NumberUtilities.java 1.7KB

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