chavdardim1990

Balanced Numbers 2

Feb 6th, 2023
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class BalancedNumbers {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. long result = 0;
  7.  
  8. while (true) {
  9. int number = scanner.nextInt();
  10. long firstDigit = number / 100;
  11. long secondDigit = (number / 10) % 10;
  12. long thirdDigit = number % 10;
  13. if (firstDigit + thirdDigit == secondDigit) {
  14. result += number;
  15. } else {
  16. break;
  17. }
  18.  
  19. }
  20.  
  21. System.out.println(result);
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment