MiniMi2022

Balanced number

Feb 15th, 2022 (edited)
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class BalancedNumbers {
  4.     public static void main(String[] args) {
  5.         Scanner myScan=new Scanner(System.in);
  6.         boolean isBalanced=true;
  7.         int sum=0;
  8.         while (isBalanced){
  9.             int number=Integer.parseInt(myScan.nextLine());
  10.             int lastDigit=number%10;
  11.             int midDigit=number/10%10;
  12.             int firstDigit=number/100;
  13.             if ((lastDigit+firstDigit)==midDigit){
  14.                 sum+=number;
  15.             }else{
  16.                 isBalanced=false;
  17.             }
  18.         }
  19.         System.out.println(sum);
  20.     }
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment