Advertisement
CR7CR7

balancedNumbers

Aug 21st, 2022
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | Source Code | 0 0
  1. import java.util.Scanner;
  2. public class BalancedNumbers {
  3.     public static void main(String[] args) {
  4.         Scanner sc = new Scanner(System.in);
  5.         int sum = 0;
  6.         boolean isBalanced ;
  7.         do {
  8.             int nextnum = Integer.parseInt(sc.nextLine());
  9.             int firstDigit = nextnum / 100;
  10.             int secondDigit = (nextnum - 100 * firstDigit)/10;
  11.             int thirdDigit = nextnum%10;
  12.             isBalanced = secondDigit == firstDigit + thirdDigit;
  13.             if (isBalanced){
  14.                 sum += nextnum;
  15.             }
  16.         }
  17.         while(isBalanced);
  18.  
  19.         System.out.println(sum);
  20.     }
  21. }
Tags: #Java
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement