Advertisement
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 sc = new Scanner(System.in);
- int sum = 0;
- boolean isBalanced ;
- do {
- int nextnum = Integer.parseInt(sc.nextLine());
- int firstDigit = nextnum / 100;
- int secondDigit = (nextnum - 100 * firstDigit)/10;
- int thirdDigit = nextnum%10;
- isBalanced = secondDigit == firstDigit + thirdDigit;
- if (isBalanced){
- sum += nextnum;
- }
- }
- while(isBalanced);
- System.out.println(sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement