find number of paths (ending at leaves) where the sum of the elements in the path is equal to the number passed : <p>Given a binary tree you need to find number of paths (ending at leaves) where the sum of the elements in the path is equal to the number passed.</p>

<p>Getting Error in my code .</p>

<p>E.g. if tree is 
      10
  5        12
4  7
and number passed is 22</p>

<p>than we have two paths 10->5->7 and 10->12 where the sum is 22. So, the answer is 2.</p>

<p>E.g. if tree is
      10
  5        12
4  7    1    3
and number passed is 22</p>

<p>than we have only one path 10->5->7 as 12 is not a leaf node and adding 1 or 3 increases the value above 22. So, the answer is 1. </p>

<p>// Java program to print to print root to leaf path sum equal to
// a given number</p>

<p>/* A binary tree node has data, pointer to left child
and a pointer to right child */</p>

<pre><code>class Node 
{
    int data;
    Node left, right;

    Node(int item) 
    {
        data = item;
        left = right = null;
    }
}

class BinaryTree {
int count =0;
    Node root;

    /*
    Given a tree and a sum, return true if there is a path from the root
    down to a leaf, such that adding up all the values along the path
    equals the given sum.

    Strategy: subtract the node value from the sum when recurring down,
    and check to see if the sum is 0 when you run out of tree.
    */

    int haspathSum(Node node, int sum) 
    {
        if (node == null)
        {
            return (count=0);
        }
        else
        {

            /* otherwise check both subtrees */
            int subsum = sum - node.data;

            if (subsum == 0 &amp;&amp; node.left == null &amp;&amp; node.right == null)
                    count = count + 1;
                    //return count;
        if node.left
                haspathSum(node.left, subsum);
                //return count;
            if (node.right)
                haspathSum(node.right, subsum);

            return count;

        }

    }


    /* Driver program to test the above functions */
    public static void main(String args[]) 
    {
        int sum = 22;

        /* Constructed binary tree is
            10
            / \
        8    2
        / \ /
        3 5 2
        */
        BinaryTree tree = new BinaryTree();
        tree.root = new Node(10);
        tree.root.left = new Node(5);
        tree.root.right = new Node(12);
        tree.root.left.left = new Node(4);
        tree.root.left.right = new Node(7);
        //tree.root.right.left = new Node(2);

//  BinaryTree ch = new BinaryTree();
            System.out.println("count = " +tree.haspathSum(tree.root,sum));
    }       

}
</code></pre>

<p>Error :--</p>

<pre><code>46: error: incompatible types: Node cannot be converted to boolean
        if (node.left)
                ^
49: error: incompatible types: Node cannot be converted to boolean
            if (node.right)
                    ^
2 errors
</code></pre>
