I could not take input for level k

see this

 static Node buildTree(Node root) {
        int d = sc.nextInt();
        int n = sc.nextInt();
        root = new Node(d);
        if (n == 0) {
            return root;
        } else if (n == 1) {
            root.left = buildTree(root.left);
            return root;
        } else {
            root.left = buildTree(root.left);
            root.right = buildTree(root.right);
            return root;
        }
    }

    public static void main(String[] args) {
        Node root = null;
        root = buildTree(root);
        int k = sc.nextInt();
        int ans = sumAtLevelK(root, k);
        System.out.println(ans);
    }

what is the error in my code?