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 myScan=new Scanner(System.in);
- boolean isBalanced=true;
- int sum=0;
- while (isBalanced){
- int number=Integer.parseInt(myScan.nextLine());
- int lastDigit=number%10;
- int midDigit=number/10%10;
- int firstDigit=number/100;
- if ((lastDigit+firstDigit)==midDigit){
- sum+=number;
- }else{
- isBalanced=false;
- }
- }
- System.out.println(sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment