Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int firstNumber = Integer.parseInt(scanner.nextLine());
- int secondNumber = Integer.parseInt(scanner.nextLine());
- int sumRightNumbers = 0;
- int sumLeftNumbers = 0;
- for (int i = firstNumber; i <= secondNumber; i++) {
- int currentNum = i;
- int first = currentNum % 10;
- currentNum /= 10;
- int second = currentNum % 10;
- currentNum /= 10;
- int third = currentNum % 10;
- currentNum /= 10;
- sumRightNumbers = first + second;
- int fourth = currentNum % 10;
- currentNum /= 10;
- int fifth = currentNum % 10;
- currentNum /= 10;
- sumLeftNumbers = fourth + fifth;
- if (sumLeftNumbers == sumRightNumbers) {
- System.out.printf("%d ", i); // or System.out.print(i + " " );
- } else if (sumLeftNumbers > sumRightNumbers){
- sumRightNumbers += third;
- if (sumLeftNumbers == sumRightNumbers) {
- System.out.printf("%d ", i); // or System.out.print(i + " " );
- }
- } else if (sumLeftNumbers < sumRightNumbers) {
- sumLeftNumbers += third;
- if (sumLeftNumbers == sumRightNumbers) {
- System.out.printf("%d ", i); // or System.out.print(i + " " );
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement