NumberUtilities.java 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import java.lang.Math;
  2. public class NumberUtilities {
  3. public static String getRange(int start) {
  4. String answer = "";
  5. for(int i = 0; i < start; i++){
  6. String myString = String.valueOf(i);
  7. answer = answer.concat(myString);
  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. String myString = String.valueOf(i);
  15. answer = answer.concat(myString);
  16. }
  17. return answer;
  18. }
  19. public static String getRange(int start, int stop, int step) {
  20. String answer = "";
  21. for(int i = start; i < stop; i += step){
  22. String myString = String.valueOf(i);
  23. answer = answer.concat(myString);
  24. }
  25. return answer;
  26. }
  27. public static String getEvenNumbers(int start, int stop) {
  28. String answer = "";
  29. for(int i = start; i < stop; i++){
  30. if(i%2 == 0){
  31. String myString = String.valueOf(i);
  32. answer = answer.concat(myString);
  33. }
  34. }
  35. return answer;
  36. }
  37. public static String getOddNumbers(int start, int stop) {
  38. String answer = "";
  39. for(int i = start; i < stop; i++){
  40. if(i%2!= 0){
  41. String myString = String.valueOf(i);
  42. answer = answer.concat(myString);
  43. }
  44. }
  45. return answer;
  46. }
  47. public static String getExponentiations(int start, int stop, int exponent) {
  48. String answer = "";
  49. for(int i = start; i <= stop; i++){
  50. int expo = (int) Math.pow(i, exponent);
  51. String myString = String.valueOf(expo);
  52. answer = answer.concat(myString);
  53. }
  54. return answer;
  55. }
  56. }