logo

Crowdly

Looking for test answers and solutions? Browse our comprehensive collection of verified answers for at moodle.lsu.edu.

Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!

Consider the code for the recursive method riddle shown in this code snippet:

public static int riddle(int n)

{

   if (n == 0)

   {

      return 0;

   {

   else

   {

      return (n + riddle(n - 1));

   }

}

To avoid infinite recursion, which of the following lines of code should replace the current terminating case? 

100%
0%
0%
0%
View this question

Consider the code for the recursive method mystery shown in this code snippet:

public static int mystery(int n)

{

   if (n == 0)

   {

      return 0;

   }

   else

   {

      return (n + mystery(n-1));

   }

}

What will be printed by the statement System.out.println(mystery(-4));? 

100%
0%
0%
0%
View this question

Complete the code for the recursive method printSum shown in this code snippet, which is intended to return the sum of digits from 1 to n:

public static int printSum(int n)

{

   if (n == 0)

   {

      return 0;

   }

   else

   {

      ______________________________

   }

}

100%
0%
0%
0%
View this question

Consider the recursive method myPrint shown in this code snippet:

public void myPrint(int n) 

{

   if (n < 10)

   {

      System.out.print(n);

   }

   else 

   {

      int m = n % 10;

      System.out.print(m);

      myPrint(n / 10);

   }

}

What does this method do?

0%
0%
0%
100%
View this question

Consider the recursive method myPrint in this code snippet:

public void myPrint(int n) 

{

   if (n < 10)

   {

      System.out.print(n);

   }

   else 

   {

      int m = n % 10;

      System.out.print(m);

      myPrint(n / 10);

   }

}

What is printed for the call myPrint(821)?

0%
0%
0%
100%
View this question

Consider the recursive method myPrint:

public void myPrint(int n) 

{

   if (n < 10)

   {

      System.out.print(n);

   }

   else 

   {

      int m = n % 10;

      System.out.print(m);

      myPrint(n / 10);

   }

}

What is printed for the call myPrint(8)?

0%
0%
0%
100%
View this question

Consider the following recursive code snippet:

public int mystery(int n, int m) 

{

   if (n == 0)

   {

      return 0;

   }

   if (n == 1)

   {

      return m;

   }

   return m + mystery(n - 1, m);

}

What value is returned from a call to mystery(3,6)?

100%
0%
0%
0%
View this question

Consider the following recursive code snippet:

public int mystery(int n, int m) 

{

   if (n == 0)

   {

      return 0;

   }

   if (n == 1)

   {

      return m;

   }

   return m + mystery(n - 1, m);

}

 

What value is returned from a call to mystery(1,5)?

0%
0%
100%
0%
View this question

Consider the following recursive code snippet:

public static int mystery(int n, int m) 

{

   if (n <= 0)

   {

      return 0;

   }

   if (n == 1)

   {

      return m;

   }

   return m + mystery(n - 1, m);

}

Identify the terminating condition(s) of method mystery? 

0%
0%
0%
100%
View this question

Consider the following code snippet for calculating Fibonacci numbers recursively:

int fib(int n) 

{  

   // assumes n >= 0

   if (n <= 1)

   {

      return n;

   }

   else

   {

      return (fib(n - 1) + fib(n - 2));

   }

}

Identify the terminating condition in this recursive method.

0%
100%
0%
0%
View this question

Want instant access to all verified answers on moodle.lsu.edu?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!