SHARE
TWEET

04. Equal Sums Even Odd Position(70/100)

a guest Mar 26th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top