Exam 11: Recursion
Exam 1: Getting Started45 Questions
Exam 2: Console Input and Output29 Questions
Exam 3: Flow of Control44 Questions
Exam 4: Defining Classes I45 Questions
Exam 5: Defining Classes II46 Questions
Exam 6: Arrays46 Questions
Exam 7: Inheritance43 Questions
Exam 8: Polymorphism and Abstract Classes43 Questions
Exam 9: Exception Handling45 Questions
Exam 10: File IO46 Questions
Exam 11: Recursion44 Questions
Exam 12: Uml and Patterns22 Questions
Exam 13: Interfaces and Inner Classes32 Questions
Exam 14: Generics and the Arraylist Class32 Questions
Exam 15: Linked Data Structures43 Questions
Exam 16: Collections,maps,and Iterators44 Questions
Exam 17: Swing I37 Questions
Exam 18: Swing II31 Questions
Exam 19: Java Never Ends26 Questions
Exam 20: Applets25 Questions
Select questions type
Write a recursive method to compute the factorial of a number.
Free
(Essay)
4.9/5
(44)
Correct Answer:
public static int factorialint n)
{
ifn < 0)
{
System.out.println"Sorry negative numbers not allowed.");
System.exit0);
}
ifn == 1)//base case
return1);
else
return n * factorialn-1));
}
The underlying data structure used by the computer during recursion is a:
Free
(Multiple Choice)
4.7/5
(43)
Correct Answer:
D
Write a recursive method to compute the power of x< sup >n< /sup > for non-negative n.
Free
(Essay)
4.8/5
(36)
Correct Answer:
public static int powerint x,int n)
{
ifn < 0)
{
System.out.println"Illegal argument to power");
System.exit0);
}
ifn > 0)
return powerx,n-1)* x);
else
return1);//base case
}
The binary search algorithm is extremely slow compared to an algorithm that simply tries all array elements in order.
(True/False)
4.9/5
(33)
The following code for the method factorial)applies to the next two questions: public static double factorial double n)
{
If n == 0)
{
Return 1;
}
Else
{
Return n * factorialn-1);
}
}
What is the value returned when the integer 3 is the argument to the factorial method?
(Multiple Choice)
5.0/5
(43)
A recursive solution can be preferable to an iterative solution because:
(Multiple Choice)
4.8/5
(39)
A recursively written method will usually run slower and use more storage than an equivalent iterative version.
(True/False)
4.8/5
(42)
Write an iterative method to compute the power of x< sup >n< /sup > for non-negative n.
(Essay)
4.8/5
(31)
What is the value returned when the integer 5 is the argument to the factorial method?
(Multiple Choice)
4.9/5
(32)
The portion of memory in which a recursive computation is stored is called a/an:
(Multiple Choice)
4.9/5
(37)
Showing 1 - 20 of 44
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)