Pleanse answer me for this java cord. Thanks #What is the output produced by the
ID: 3733739 • Letter: P
Question
Pleanse answer me for this java cord. Thanks
#What is the output produced by the following?
public static void cheers(int n) {
if (n <= 1)
System.out.println("Hurrah");
else {
System.out.println("Hip");
cheers(n-1);
}
}
##Using the method inorderPrint in IntBTNode.java (also shown below) as an example, implement the method int sum() which sums all the items in a tree.
public class IntBTNode {
private int data;
private IntBTNode left, right;
}
public void inorderPrint() {
if (left != null)
left.inorderPrint();
System.out.println(data);
if (right != null)
right.inorderPrint();
##Assume StrBTNode is defined as below, write a method boolean search(String target) to search the binary tree to determine if a string exists in the tree.
public class StrBTNode {
private String data;
private IntBTNode left, right;
}
public boolean search(String target) {
}
Explanation / Answer
public static void cheers(int n) {
if (n <= 1)
System.out.println("Hurrah");
else {
System.out.println("Hip");
cheers(n-1);
}
}
Lets say n = 2 :
It prints Hip Hurrah
Lets say n = 3 :
It prints Hip Hip Hurrah
================================================================
SUM = 0;
public void inorderPrint() {
if (left != null)
left.inorderPrint();
SUM = SUM + data;
if (right != null)
right.inorderPrint();
}
System.out.println(SUM)
==================================================================
public boolean Search(String target) {
if (left != null)
left.Search();
if(target.equals(data))
return true;
if (right != null)
right.Search();
return false;
}