Advertisement
Guest User

04. Equal Sums Even Odd Position

a guest
Mar 26th, 2019
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. package Topic6_NestedLoopsExercise;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Pb4_EqualSumsEvenOddPosition {
  6.     public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);
  8.  
  9.         int num1 = Integer.parseInt(input.nextLine());
  10.         int num2 = Integer.parseInt(input.nextLine());
  11.  
  12.         while (num1<=num2){
  13.             int sumEVEN = 0;
  14.             int sumODD=0;
  15.             int x =num1;
  16.             for (int digit=6;digit>0;digit--){
  17.                 if (digit%2==0){
  18.                     sumEVEN+=x%10;
  19.                 }else{
  20.                     sumODD+=x%10;
  21.                 }
  22.                 x/=10;
  23.             }
  24.             if (sumEVEN==sumODD){
  25.                 System.out.print(num1 + " ");
  26.             }
  27.             num1++;
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement