1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Leona [35]
3 years ago
7

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)); a. 1 b. 18 c. 27 d. 32
Computers and Technology
1 answer:
ozzi3 years ago
5 0

Answer:

c. 27

Explanation:

  • In recursion method, a method calls itself until a condition becomes true and returned back. In mystery(), at first time, first is 0 and last is 4. Condition is checked and 0!=4 so else part is executed in which again mystery is called with first as 1 and last 4. This will go again and again until first=4.
  • When first=4 it is also equal to last so if part is executed and alpha[4] is returned which is 9, now it comes alpha[3] +9 which is 8+9 =17 .
  • It is returning values to its previous calls that is why it will reduce to alpha[0]+alpha[1]+alpha[2]+17 which is nothing but sum of all elements of a alpha
  • Then, 1+4+5+8+9=27.
You might be interested in
What set of code correctly initializes all elements of the array ar to the value 0, given the declaration
Veronika [31]

Answer:

The correct answer is:

C. ndx = 0;

while (ndx < 3) {

ar[ndx] = 0;

ndx++;

}

Explanation:

The declaration given is:

int ar[3];

This means the array consists of three locations and is named as ar.

We know that the indexes are used to address the locations of an array and the index starts from 0 and goes upto to 1 less than the size of the array which means the indexes of array of 3 elements will start from 0 and end at 2.

Now in the given options we are using ndx variable to run the while loop.

So the code to assign zero to all elements of array will be

ndx = 0;

while(ndx<3)

{

ar[ndx] = 0;

ndx++;

}

Hence, the correct answer is:

C. ndx = 0;

while (ndx < 3) {

ar[ndx] = 0;

ndx++;

}

7 0
2 years ago
Q1: Which of the following is an input peripheral device?
faltersainse [42]

Answer:

Mouse

Explanation:

Input devices allow users to input something in the computer. For example keyboard allows users to type on the computer, or mouse allows users to click.

On the other hand output devices allow computers to output data. For example speakers allow us to hear the outputs of a computer.

3 0
3 years ago
Read 2 more answers
Research: "How was your experience on site '4chan'?"<br><br> Please answer in the box below.
olganol [36]

Answer:

My experience was comfortable

Explanation:

This website is pretty simple and loads fast, there are a lot of images with high quality but only when you click over of the image this expands in the original size.

I could find really helpful information, there are different subjects, but this is not a website for kids for some adult content.

I didn't need to register any information to share content or if you want to ask something and everything is anonymous.

5 0
3 years ago
Write a java program as follows Write a method called powOfTwo that takes an integer as parameter, computes, and outputs it’s sq
Kisachek [45]

Answer:

public static int powOfTwo(int input) {

 return input*input;

}

You will have to call this method in main
for printing it, write

System.out.println(powOfTwo(your number));

in public static void main(str[]args) {

}

8 0
2 years ago
Which of the following components helps to limit the front-to-back movement of the crankshaft? 
iris [78.8K]
The correct answer is A. The thrust bearing

It is used to help limit the front-to-back movement of the crankshaft.
5 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following best explains why some people invest their saving in the stock market and others put their saving in bank
    5·2 answers
  • Which button is used to open the Start menu in Windows Vista?
    14·1 answer
  • list six external parts or peripherals of a computer system and identify which are output and which are input devices
    8·1 answer
  • Which icon is greater in file size? (Show your working)
    8·1 answer
  • Enables businesses and consumers to share data or use software applications directly from a remote server over the Internet or w
    6·1 answer
  • What are some good electronics that I can buy on Amazon?
    14·1 answer
  • What is the output of the code snippet given below?string s = "abcde";int i = 1;while (i &lt; 5){ cout &lt;&lt; s.substr (i, 1);
    11·1 answer
  • Which practice is the safest way to sit at a desk while typing on the computer?
    12·1 answer
  • Package Newton’s method for approximating square roots (Case Study: Approximating Square Roots) in a function named newton. This
    14·1 answer
  • Discussion Topic
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!