View difference between Paste ID: ctLUHFep and Ys6RLTMJ
SHOW: | | - or go back to the newest paste.
1
package com.company;
2
import java.util.Scanner;
3
4
public class Main {
5
6
    public static void main(String[] args) {
7
        Scanner scanner = new Scanner(System.in);
8
9
        int n = Integer.parseInt(scanner.nextLine());
10
        int m = Integer.parseInt(scanner.nextLine());
11
12
        for (int i = n; i <= m; i++) {
13
            int oddSum = 0;
14
            int evenSum = 0;
15
16
            String currentNum = "" + i; // текущото число го записвам в String
17
            for (int j = 0; j < 6; j++) {
18
                if (j % 2 == 0) {
19
                    evenSum += currentNum.charAt(j); // на currentNum ми вземи позиция j
20
                } else {
21
                    oddSum += currentNum.charAt(j);
22
                }
23
            }
24
            if (oddSum == evenSum) {
25
                System.out.print(i + " ");
26
            }
27
        }
28
    }
29
}
30