aneliabogeva

SumOddEvenPossition

Nov 26th, 2020
515
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class EqualSumEvenOddPossisition {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String n1 = scanner.nextLine();
  7.         String n2 = scanner.nextLine();
  8.         Integer evenPossistion = 0;
  9.         Integer oddPossition = 0;
  10.  
  11.         for (int i = Integer.valueOf(n1); i <= Integer.valueOf(n2); i++){
  12.             String value = String.valueOf(i);
  13.             for(int j = 1; j <= value.length(); j++){
  14.                 Character currentDigit = value.charAt(j-1);
  15.                 Integer digit = Character.getNumericValue(currentDigit);
  16.                 if(j % 2 == 0){
  17.                     evenPossistion += digit;
  18.                 }else{
  19.                     oddPossition += digit;
  20.                 }
  21.             }
  22.             if(oddPossition == evenPossistion){
  23.                 System.out.printf("%s ",i);
  24.             }
  25.             oddPossition = 0;
  26.             evenPossistion = 0;
  27.         }
  28.  
  29.     }
  30. }
  31.  
RAW Paste Data