Advertisement
Spocoman

02. Equal Sums Even Odd Position

Aug 30th, 2024
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class EqualSumsEvenOddPosition {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int startNum = Integer.parseInt(scanner.nextLine()),
  7.                 endNum = Integer.parseInt(scanner.nextLine());
  8.  
  9.         for (int i = startNum; i <= endNum; i++) {
  10.             int odd = 0, even = 0, digit = i;
  11.  
  12.             for (int x = 0; x < 6; x++) {
  13.                 if (x % 2 == 0) {
  14.                     even += digit % 10;
  15.                 } else {
  16.                     odd += digit % 10;
  17.                 }
  18.                 digit /= 10;
  19.             }
  20.  
  21.             if (odd == even) {
  22.                 System.out.printf("%d ",i);
  23.             }
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement