NumberUtilities.java 1.4KB

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