Advertisement
Guest User

Untitled

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