Advertisement
galinyotsev123

ProgBasics07Nested-Loops-Y05equalSumsEvenOddPosition3

Feb 2nd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int firstNumber = Integer.parseInt(scanner.nextLine());
  8. int secondNumber = Integer.parseInt(scanner.nextLine());
  9.  
  10. for (int i = firstNumber; i <= secondNumber; i++) {
  11. int currentNum = i;
  12.  
  13. int first = currentNum % 10;
  14. currentNum /= 10;
  15. //123456
  16. int second = currentNum % 10;
  17. currentNum /= 10;
  18. //12345
  19. int third = currentNum % 10;
  20. currentNum /= 10;
  21. //1234
  22. int fourth = currentNum % 10;
  23. currentNum /= 10;
  24. //123
  25. int fifth = currentNum % 10;
  26. currentNum /= 10;
  27. //12
  28.  
  29. if (first + third + fifth == second + fourth + currentNum) {
  30. System.out.printf("%d ", i); // or System.out.print(i + " " );
  31. }
  32.  
  33. }
  34.  
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement