Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class EqualSumsLeftRightPosition {
  4. public static void main(String[] args) {
  5.  
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. int one = Integer.parseInt(scanner.nextLine());
  9. int two = Integer.parseInt(scanner.nextLine());
  10.  
  11.  
  12. for (int a = one; a <= two; a++) {
  13. int left = 0;
  14. int middle = 0;
  15. int right = 0;
  16.  
  17. for (int b = 0; b <= Integer.toString(a).length() - 1; b++) {
  18. int num = Integer.toString(a).charAt(b) - 48;
  19.  
  20. if (b <= 1) {
  21. left += num;
  22. } else if (b >= 3){
  23. right += num;
  24. }else {
  25. middle += num;
  26. }
  27.  
  28. }
  29. if (left == right || (Math.min(left, right) + middle == Math.max(left, right))) {
  30. System.out.printf("%d ", a);
  31. }
  32.  
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement