Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class BalancedNumbers {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- long result = 0;
- while (true) {
- int number = scanner.nextInt();
- long firstDigit = number / 100;
- long secondDigit = (number / 10) % 10;
- long thirdDigit = number % 10;
- if (firstDigit + thirdDigit == secondDigit) {
- result += number;
- } else {
- break;
- }
- }
- System.out.println(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment