NumberUtilities.java 1.4KB

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