NumberUtilities.java 1.6KB

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