Question: (20 pts) Fill in the missing code: This recursive method returns even if the length of a give String is even, and odd if the
(20 pts) Fill in the missing code:
This recursive method returns even if the length of a give String is even, and odd if the length of the String is odd.
public static String foo(String s)
{
if (s.length() ==0)
return even;
else if (s.length() = = 1)
return odd;
else
//your code goes here
}
(40 pts) You coded the following in the file Test.java :
System.out.println( foo(5));
//more code here
public static int foo(int n) //line 9
{
if (n = = 0)
return 1;
else
System.out.println(n* foo(n-1) );
} //line 15
At compile time, you get the following error:
Text.java: 15: missing return statement
} //line 15
^
1 error
Explain what the problem is and how to fix it.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
