Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class EqualSumsEvenOddPosition {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int firstNum = Integer.parseInt(scan.nextLine());
- int secondNum = Integer.parseInt(scan.nextLine());
- for (int i = firstNum; i <= secondNum; i++){
- String currentNum =""+ i;
- int oddsum = 0;
- int evenSum = 0;
- for (int j = 0; j < currentNum.length();j++){
- int currentDigit = Integer.parseInt(""+ currentNum.charAt(j));
- if (j % 2 == 0){
- evenSum += currentDigit;
- } else {
- oddsum +=currentDigit;
- }
- }
- if (oddsum == evenSum){
- System.out.print(i +" ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement