class
GFG
{
static
class
Node
{
int
data;
Node left;
Node right;
};
static
Node newNode(
int
data)
{
Node node =
new
Node();
node.data = data;
node.left = node.right =
null
;
return
(node);
}
static
class
Int
{
int
a;
}
static
void
findProductSum(Node root, Int prod, Int sum)
{
if
(root ==
null
|| (root.left ==
null
&& root.right ==
null
))
return
;
if
(root.left !=
null
|| root.right !=
null
)
{
prod.a *= root.data;
sum.a += root.data;
}
findProductSum(root.left, prod, sum);
findProductSum(root.right, prod, sum);
}
public
static
void
main(String args[])
{
Node root = newNode(
1
);
root.left = newNode(
2
);
root.right = newNode(
3
);
root.left.left = newNode(
4
);
root.left.right = newNode(
5
);
Int prod =
new
Int();prod.a =
1
;
Int sum =
new
Int(); sum.a =
0
;
findProductSum(root, prod, sum);
System.out.print(
"Product = "
+ prod.a +
" , Sum = "
+ sum.a);
}
}