Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int output = 0;
- while (true) {
- int input = scanner.nextInt();
- if (input > 99 && input < 1000 && isBalanced(input)) {
- output += input;
- }
- }
- System.out.println(output); // Unreachable statement ???
- }
- public static boolean isBalanced(int a) { // a = 132
- int first = (a - a % 100) / 100; //1
- int second = (a % 100) / 10; //3
- int third = a % 10; //2
- if (first+third == second){
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement