Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package L06_NestedLoops;
- import java.util.Scanner;
- public class P02_SumsEvenOddPosition {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int firstNumber = Integer.parseInt(scanner.nextLine());
- int secondNumber = Integer.parseInt(scanner.nextLine());
- //правим фор цикъл -> преминаваме през всички числа от първото до последното
- for (int currentNumber = firstNumber; currentNumber <= secondNumber ; currentNumber++) {
- //намираме първото, второто... шестото число
- int firstDigit = currentNumber / 100000;
- int secondDigit = currentNumber / 10000 % 10;
- int thirdDigit = currentNumber / 1000 % 10;
- int fourthDigit = currentNumber / 100 % 10;
- int fifthDigit = currentNumber / 10 % 10;
- int sixthDigit = currentNumber % 10;
- int oddSum = firstDigit + thirdDigit + fifthDigit;
- int evenSum = secondDigit + fourthDigit + sixthDigit;
- //проверяваме дали сумата на четните е равна на сумата на нечетните
- if(oddSum == evenSum){
- System.out.printf("%d ", currentNumber);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement