1) int multiply(int a, int b){ if (a == 0){ return 0; }else { return b + multipl
ID: 3622354 • Letter: 1
Question
1) int multiply(int a, int b){if (a == 0){
return 0;
}else
{
return b + multiply(a-1, b);
}
}
2) void printScientificNotation(double value, int powerOfTen){
if (value >= 1.0 && value < 10.0){
System.out.println(value + " x 10^" + powerOfTen);
}
else if (value < 1.0){
printScientificNotation(value * 10, powerOfTen - 1);
}
else // value >= 10.0{
printScientificNotation(value / 10, powerOfTen + 1);
}
}
3)IntNode delete(IntNode head, int target){
if (head == null){
return null;
}
else if (head.data == target){
return head.next;
}
else
{
head.next = delete(head.next, target);
return head;
}
}
4)IntNode interleave(IntNode head1, IntNode head2){
if (head1 == null){
return head2;
}
else{
head1.next = interleave(head2, head1.next);
return head1;
}
}
5)int differenceInLengths(IntNode head1, IntNode head2){
if (head1 == null && head2 == null)
{
return 0;
}
else if (head1 == null && head2 != null){
return 1 + differenceInLengths(null, head2.next);
}
else if (head1 != null && head2 == null){
return 1 + differenceInLengths(head1.next, null);
}
else{
return differenceInLengths(head1.next, head2.next);
}
}