Programming

Consider the following code.
public static int recur3(int n) {
if (n == 0) return 0;
if (n == 1) return 1;
if (n == 2) return 2;
return recur3(n - 1) + recur3(n - 2) + recur3(n - 3);
}
What value would be returned if this method were called and passed a value of 5?
3
9
11
16

  1. 👍 0
  2. 👎 0
  3. 👁 96
  1. from the last statement,
    r(5) = r(4)+r(3)+r(2)
    r(4) = r(3)+r(2)+r(1)
    r(3) = r(2)+r(1)+r(0)
    So do the math

Respond to this Question

First Name

Your Response

Similar Questions

  1. computer science

    9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should

    asked by Cheryl on February 18, 2012
  2. Java Programming

    1. What is Java SE? A. Java Standard Edition* B. Java Software Editor C. Java Scientific Edition D. Java Software Emulator 2. Which of the following is the correct header for the main method of a Java program? A. public static

    asked by Nick Torres on December 11, 2019
  3. java programming

    Dice Game Write a program that plays a simple dice game between the computer and the user. When the program runs, a loop should repeat 10 times. Each iteration of the loop should do the following: Generate a random integer in the

    asked by anonymous on May 28, 2020
  4. calculus

    use symmetry to evaluate the double integral (1+x^2siny+y^2sinx)dA, R=[-pi,pi]x[-pi,pi]. let g(x) and h(y) be two functions: int(c to d)int(a to b)(g(x,y)+h(x,y))dxdy=int(c to d)int(a to b)g(x,y)dxdy+int(c to d)int(a to

    asked by Inna on November 9, 2015
  5. Science/Computer Programming

    The purpose of this exercise is to practice reading code and recognizing the traversal patterns in this chapter. The following methods are hard to read, because instead of using meaningful names for each variable and method, they

    asked by Anonymous on February 8, 2019
  1. Programming

    Here is the source code for the Kitty class: public class Kitty { String name; int age; public Kitty(){ } public void setName(String n){ name = n; } public String getName(){ return name; } public void setAge(int a){ age = a; }

    asked by Rob on October 28, 2009
  2. C programming

    Enter two integers between 1 to 10 3 4 Both numbers are less than 5. The sum of two numbers is:-1081825676 The product of two numbers is:-1081825680 why are the sum and product so weird? my code: #include int main() { int x; int

    asked by jen on October 9, 2008
  3. programming

    m trying to create an arraylist that's sorted but I have no idea how to sort the numbers. I cant use the array.sort method here is my code: public class Testing { private int [] data; private int count; private static int

    asked by Adam on February 24, 2013
  4. Java programming

    how do i add prime numbers in this java code: public class PrimeNumbers { public static void main(String[] args) { int[] array = new int[10]; Scanner in = new Scanner(System.in); System.out.println("Enter the elements of the

    asked by anonymous on April 7, 2019
  5. Programming

    Consider the following code. public void printNumbers(int x, int y) { if (x < 5) { System.out.println("x: " + x); } if (y > 5) { System.out.println("y: " + y); } int a = (int)(Math.random() * 10); int b= (int)(Math.random() * 10);

    asked by ... on April 10, 2020

You can view more similar questions or ask a new question.