Where did i get wrong showing right ans only for 2 test cases

import java.util.*;
public class Main {

static Scanner scn = new Scanner(System.in);

public static void main(String[] args) {
	Main m = new Main();
	BinaryTree bt = m.new BinaryTree();
	System.out.println(bt.isBalanced());
}

private class BinaryTree {
	private class Node {
		int data;
		Node left;
		Node right;
	}

	private Node root;
	private int size;

	public BinaryTree() {
		this.root = this.takeInput(null, false);
	}

	public Node takeInput(Node parent, boolean ilc) {

		int cdata = scn.nextInt();
		Node child = new Node();
		child.data = cdata;
		this.size++;

		// left
		boolean hlc = scn.nextBoolean();

		if (hlc) {
			child.left = this.takeInput(child, true);
		}

		// right
		boolean hrc = scn.nextBoolean();

		if (hrc) {
			child.right = this.takeInput(child, false);
		}

		// return
		return child;
	}

	public boolean isBalanced() {
		return this.isBalanced(this.root);
	}

	private boolean isBalanced(Node node) {
		// write your code here
        if((node.left == null && node.right!=null) || (node.right==null && node.left!=null)){
            return false;
        }else if(node.left!=null ){
            return isBalanced(node.left);
            
            }else if(node.right!=null){
                return isBalanced(node.right);
            }
          else{
              return true;
          }  
        }
	}

	// private class BalancedPair {
	// 	int height;
	// 	boolean isBalanced;
	// }

}

Hey @Vishu_1801
You are doing Wrong
2 true 3 false false false
correct output : true
your code gives false
2
/
3
it is balanced