NumberUtilities.java 1.7KB

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