NumberUtilities.java 1.7KB

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