NumberUtilities.java 1.4KB

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