Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class EqualSumsLeftRightPosition {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int firstNum = Integer.parseInt(scanner.nextLine());
- int secondNum = Integer.parseInt(scanner.nextLine());
- for (int i = firstNum; i <= secondNum; i++) {
- String currentDigit = "" + i;
- int leftSum = 0;
- int rightSum = 0;
- int middleDigit = 0;
- for (int j = 0; j < currentDigit.length(); j++) {
- int currentNum = Integer.parseInt("" + currentDigit.charAt(j));
- if (j <= 2) {
- leftSum += currentNum;
- } else if (j >= 4) {
- rightSum += currentNum;
- } else {
- middleDigit = currentNum;
- }
- if (leftSum == rightSum) {
- System.out.print(i + " ");
- } else if (leftSum > rightSum) {
- rightSum += middleDigit;
- } else {
- leftSum += middleDigit;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement