Advertisement
veronikaaa86

02. Equal Sums Even Odd Position - v.02

Feb 13th, 2022
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 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 firstNum = Integer.parseInt(scanner.nextLine());
  8. int secondNum = Integer.parseInt(scanner.nextLine());
  9.  
  10. for (int i = firstNum; i <= secondNum; i++) {
  11. String currentNum = "" + i;
  12.  
  13. int evenSum = 0;
  14. int oddSum = 0;
  15. for (int j = 0; j < 6; j++) {
  16. int digit = Integer.parseInt("" + currentNum.charAt(j));
  17.  
  18. if (j % 2 == 0) {
  19. evenSum = evenSum + digit;
  20. } else {
  21. oddSum = oddSum + digit;
  22. }
  23. }
  24. if (evenSum == oddSum) {
  25. System.out.print(currentNum + " ");
  26. }
  27. }
  28. }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement