NumberUtilities.java 1.2KB

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