Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class EqualSumEvenOddPossisition {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String n1 = scanner.nextLine();
- String n2 = scanner.nextLine();
- Integer evenPossistion = 0;
- Integer oddPossition = 0;
- for (int i = Integer.valueOf(n1); i <= Integer.valueOf(n2); i++){
- String value = String.valueOf(i);
- for(int j = 1; j <= value.length(); j++){
- Character currentDigit = value.charAt(j-1);
- Integer digit = Character.getNumericValue(currentDigit);
- if(j % 2 == 0){
- evenPossistion += digit;
- }else{
- oddPossition += digit;
- }
- }
- if(oddPossition == evenPossistion){
- System.out.printf("%s ",i);
- }
- oddPossition = 0;
- evenPossistion = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment