NumberUtilities.java 1.5KB

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