Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package S6_NestedLoops;
- import java.util.Scanner;
- public class EqualSumsEvenOddPosition {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int numFirst = Integer.parseInt(scanner.nextLine());
- int numSecond = Integer.parseInt(scanner.nextLine());
- for (int i = numFirst; i <= numSecond; i++) {
- int currentNum = i;
- int sumEven = 0;
- int sumOdd = 0;
- for (int j = 0; j < 6; j++) {
- int lastDigit = currentNum % 10;
- currentNum = currentNum / 10;
- if(j % 2 == 0) {
- sumEven += lastDigit;
- } else {
- sumOdd += lastDigit;
- }
- }
- if(sumEven == sumOdd) {
- System.out.print(i + " ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement