SvetlanPetrova

EqualSumsEvenOddPosition SoftUni

May 24th, 2021
801
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
Advertisement
Add Comment
Please, Sign In to add comment