Question
Can someone help with these multiple choice questions please? 2. Consider the recursive method myPrint. What does this method do? public void myPrint(int n) {
Can someone help with these multiple choice questions please?
2. Consider the recursive method myPrint. What does this method do?
public void myPrint(int n)
{
if (n < 10)
System.out.print(n);
else
{
int m = n % 10;
System.out.print(m);
myPrint(n/10);
}
}
A) Prints a positive int value forward, digit by digit.
B) Prints a positive int value backward, digit by digit.
C) Adds the digits of an int and prints it out.
D) Divides the int by 10 and prints it out.
13. A terminating condition for a recursive method that finds the middle character of a String with any number of characters could be due to which of the following condition(s):
I the length of the String is 1
II first and last String characters match
III the String is not empty
A) I
B) II
C) I, II and III
D) I and III
14. Which statements are true?
I Recursion is faster then iteration
II Recursion is often easier to understand than iteration
III Recursive design has an economy of thought
A) I
B) I and II
C) II and III
D) I and III
15. Consider the method powerOfTwo. How many recursive calls are made from the original call of powerOfTwo(63) (not including the original call)?
public boolean powerOfTwo(int n)
{
if (n == 1) // line #1
return true;
else
if (n % 2 == 1) // line #2
return false;
else
return powerOfTwo(n/2); // line #3
}
A) 6
B) 4
C) 1
D) 0
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started