yovkovbpfps

Nested LOOPS EQUAL SUMS EVEN ODD POSTION

Apr 16th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Pb4_EqualSumsEvenOddPosition {
  4. public static void main(String[] args) {
  5. Scanner input = new Scanner(System.in);
  6.  
  7. int num1 = Integer.parseInt(input.nextLine());
  8. int num2 = Integer.parseInt(input.nextLine());
  9.  
  10. while (num1<=num2){
  11. int sumEVEN = 0;
  12. int sumODD=0;
  13. int x =num1;
  14. for (int digit=6;digit>0;digit--){
  15. if (digit%2==0){
  16. sumEVEN+=x%10;
  17. }else{
  18. sumODD+=x%10;
  19. }
  20. x/=10;
  21. }
  22. if (sumEVEN==sumODD){
  23. System.out.print(num1 + " ");
  24. }
  25. num1++;
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment