Guest User

Untitled

a guest
Oct 26th, 2018
209
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package nestedLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class EqualSumsEvenOddPosition {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int num1 = Integer.parseInt(scanner.nextLine());
  9.         int num2 = Integer.parseInt(scanner.nextLine());
  10.  
  11.  
  12.         for (; num1 <= num2; num1++) {
  13.             String num1Str = Integer.toString(num1);
  14.             int oddSum = 0;
  15.             int evenSum = 0;
  16.  
  17.             for (int i = 0; i <= num1Str.length() - 1; i++) {
  18.                 if (i % 2 != 0) {
  19.                     int oddNum = num1Str.charAt(i) - 48;
  20.                     oddSum += oddNum;
  21.                 }
  22.                 if (i % 2 == 0) {
  23.                     int evenNum = num1Str.charAt(i) - 48;
  24.                     evenSum += evenNum;
  25.                 }
  26.             }
  27.             if (oddSum == evenSum) {
  28.                 System.out.print(num1);
  29.                 System.out.print(" ");
  30.             }
  31.         }
  32.     }
  33. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×