NumberUtilities.java 1.4KB

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