Advertisement
Mr_Linnenburger

AdventOfCodeDay4-2019

Dec 5th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1.  
  2.  
  3. public class Day4Problem1
  4. {
  5. public static void main(){
  6.  
  7. int count = 0;
  8. for(int i = 178416; i <= 676561; i++){
  9.  
  10. if(checkNum(i))
  11. count++;
  12.  
  13. }
  14.  
  15. System.out.println(count);
  16. }
  17.  
  18.  
  19. public static boolean checkNum(int n){
  20. boolean hasDouble = false;
  21. int current;
  22. int next;
  23. while(n > 0){
  24. current = n%10;
  25. n /= 10;
  26. next = n%10;
  27.  
  28. if(next > current)
  29. return false;
  30. else if(current == next)
  31. hasDouble = true;
  32.  
  33. }
  34. return hasDouble;
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement