NumberUtilities.java 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. public class NumberUtilities {
  2. public static String getRange(int stop) {
  3. String result = "";
  4. for ( int i = 0; i < stop; i++){
  5. 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 placeNumber = "";
  18. for (int i = start; i<stop; i = i + step){
  19. placeNumber= placeNumber + i;
  20. }
  21. return placeNumber;
  22. }
  23. public static String getEvenNumbers(int start, int stop) {
  24. String resultsProvided = "";
  25. for (int i = start; i <stop; i++) {
  26. if (i % 2 == 0) {
  27. resultsProvided = resultsProvided +i;
  28. }
  29. }
  30. return resultsProvided;
  31. }
  32. public static String getOddNumbers(int start, int stop) {
  33. String oddNumberReturned = "";
  34. for(int i = start; i < stop; i++) {
  35. if(i % 2 != 0){
  36. oddNumberReturned = oddNumberReturned + i;
  37. }
  38. }
  39. return oddNumberReturned;
  40. }
  41. public static String getExponentiations(int start, int stop,int exponent) {
  42. String results = "";
  43. for (int i = start; i <= stop; i++){
  44. results = results + (int)Math.pow(i,exponent);
  45. }
  46. return results;
  47. }
  48. }