NumberUtilities.java 1.4KB

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