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+=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+=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+=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+=2){
  26. int stuff = i;
  27. if (i%2==0){
  28. stuff = i;
  29. }else{
  30. stuff = i+1;
  31. }
  32. result+=stuff;
  33. }
  34. return result;
  35. }
  36. public static String getOddNumbers(int start, int stop) {
  37. String result = "";
  38. for (int i=start;i<stop;i+=2){
  39. result+=i;
  40. }
  41. return result;
  42. }
  43. public static String getExponentiations(int start, int stop, int exponent) {
  44. String result = "";
  45. for (int i=start;i<=stop;i++){
  46. int stuff = i;
  47. for (int j=1;j<exponent;j++){
  48. stuff *=i ;
  49. }
  50. result += stuff;
  51. }
  52. return result;
  53. }
  54. }