Advertisement
Guest User

YOLO

a guest
Mar 2nd, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Scanner;
  4.  
  5. class felbonto {
  6.  
  7. public int felbont(Integer szam, int kitevo) {
  8. List<Integer> l = new ArrayList<>();
  9. int sum = 0;
  10.  
  11. String tmp = szam.toString();
  12.  
  13. for(Character c : tmp.toCharArray()) {
  14. l.add(Integer.parseInt(c.toString()));
  15. }
  16. for(int i : l) {
  17. if(i != 0) {
  18. sum += Math.pow(i, kitevo);
  19. }
  20. }
  21.  
  22. return sum;
  23. }
  24. }
  25.  
  26. public class Main {
  27.  
  28. public static void main(String[] args) {
  29.  
  30. felbonto f = new felbonto();
  31. Scanner be = new Scanner(System.in);
  32. List<Integer> li = new ArrayList<>();
  33.  
  34. int a,b, sum, felbontva;
  35.  
  36. while(be.hasNext()) {
  37. sum = 0;
  38. a = be.nextInt();
  39. b = be.nextInt();
  40. for(Integer i = a; i <= b; i++) {
  41. if(i < 10) {
  42. sum += 1;
  43. continue;
  44. }
  45. int j = i.toString().length();
  46. // for(int j = 1; j < 6; j++) {
  47. felbontva = f.felbont(i, j);
  48. if(i == felbontva) {
  49. sum += 1;
  50. }
  51. // }
  52. }
  53. li.add(sum);
  54. }
  55. be.close();
  56.  
  57. for(int i : li)
  58. System.out.println(i);
  59. }
  60.  
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement