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());
- for (int i = firstNumber; i <= secondNumber; i++) {
- int currentNum = i;
- int first = currentNum % 10;
- currentNum /= 10;
- //123456
- int second = currentNum % 10;
- currentNum /= 10;
- //12345
- int third = currentNum % 10;
- currentNum /= 10;
- //1234
- int fourth = currentNum % 10;
- currentNum /= 10;
- //123
- int fifth = currentNum % 10;
- currentNum /= 10;
- //12
- if (first + third + fifth == second + fourth + currentNum) {
- System.out.printf("%d ", i); // or System.out.print(i + " " );
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement