SHARE
TWEET

java

a guest Dec 9th, 2019 123 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import javax.print.DocFlavor;
  2. import java.util.Scanner;
  3.  
  4. public class EqualSumsEvenOddPosition {
  5.     public static void main(String[] args) {
  6.         Scanner scan = new Scanner(System.in);
  7.         int firstNum = Integer.parseInt(scan.nextLine());
  8.         int secondNum = Integer.parseInt(scan.nextLine());
  9.         for (int i = firstNum; i <= secondNum; i++){
  10.             String currentNum =""+ i;
  11.             int oddsum = 0;
  12.             int evenSum = 0;
  13.             for (int j = 0; j < currentNum.length();j++){
  14.                 int currentDigit = Integer.parseInt(""+ currentNum.charAt(j));
  15.                 if (j % 2 ==0){
  16.                     oddsum += currentDigit;
  17.                 } else  {
  18.                    evenSum +=currentDigit;
  19.                 }
  20.             }
  21.             if (oddsum == evenSum){
  22.                 System.out.println(i +"");
  23.             }
  24.         }
  25.     }
  26. }
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
 
Top