14.2k views
5 votes
Consider the following definition of a recursive method. public static int mystery(int[] list, int first, int last) { if (first == last) return list[first]; else return list[first] + mystery(list, first + 1, last); } Given the declaration int[] alpha = {1, 4, 5, 8, 9}; What is the output of the following statement? System.out.println(mystery(alpha, 0, 4));

User Lan
by
8.5k points

1 Answer

5 votes

Answer:

Output:

27

Step-by-step explanation:

Here, in the following function of the recursion in tha Java Programming Language.

  • Define a function "mystery()" and pass two integer type argument and one integer array type argument.
  • Set the if statement and check condition is the variable "first" is equal to the variable "last" then, return the first element of the array.
  • Otherwise, it returns the addition of first to the last element and then again.
User Bobsmells
by
8.2k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.