Advertisement
veronikaaa86

02. Equal Sums Even Odd Position

Feb 13th, 2022
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. package NestedLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P02EqualSumsEvenOddPosition {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int firstNum = Integer.parseInt(scanner.nextLine());
  10. int secondNum = Integer.parseInt(scanner.nextLine());
  11.  
  12. for (int i = firstNum; i <= secondNum; i++) {
  13. int currentNum = i;
  14.  
  15. int evenSum = 0;
  16. int oddSum = 0;
  17. for (int j = 6; j >= 1; j--) {
  18. int digit = currentNum % 10;
  19.  
  20. if (j % 2 == 0) {
  21. evenSum = evenSum + digit;
  22. } else {
  23. oddSum = oddSum + digit;
  24. }
  25.  
  26. currentNum = currentNum / 10;
  27. }
  28. if (evenSum == oddSum) {
  29. System.out.print(i + " ");
  30. }
  31. }
  32. }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement