Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. package LoopsInLoops_exercise;
  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.        
  9.         int num1= Integer.parseInt(scanner.nextLine());
  10.         int num2= Integer.parseInt(scanner.nextLine());
  11.         int sum1=0;
  12.         int sum2=0;
  13.  
  14.         String first ;
  15.  
  16.         for (; num1 <=num2 ; num1++) {
  17.             first= num1+"";
  18.             for (int i = 1; i <=6 ; i++) {
  19.                 if(i%2==0){
  20.                     sum1+=Integer.parseInt((first.charAt(i-1)+""));
  21.  
  22.  
  23.                 }else{
  24.                     sum2+=Integer.parseInt((first.charAt(i-1)+""));
  25.                 }
  26.  
  27.  
  28.             }
  29.             if(sum1==sum2) System.out.print(num1+" ");
  30.  
  31.  
  32.             sum1 =0;
  33.             sum2 = 0;
  34.            
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement