Ihatemath8027 Ihatemath8027
  • 08-06-2021
  • Computers and Technology
contestada

Consider the following method:

public void doSomething(int n) {
if (n > 0) {
doSomething(n/2);
StdOut.print(n);
doSomething(n/2); }
}

How many recursive calls are made by doSomething(n)?

Respuesta :

sandlee09
sandlee09 sandlee09
  • 10-06-2021

Answer:

two recursive calls are made

Explanation:

In this piece of code two recursive calls are made by doSomething(n). This is assuming that the input (n) is greater than 0. Otherwise the function will simply end because it will completely skip over the IF statement which holds the entirety of the functions code. A recursive call is represented as the name of the function/method itself within itself. Therefore, everytime the code states doSomething(n) or in this case doSomething(n/2) it is calling itself.

Answer Link

Otras preguntas

Atomic mass is determined by the number of protons plus the number of _____. A. Electrons B. Neutrons C. Charges D. Atoms
which one is bigger 45% or 21/50 or 0.43 or 89%
Does anyone read hobbit? What is the name of Bilbo’s hillside home? a) Bag End b) Crookhollow Bend c) Brandywine End d) Lothlorien
How do I find the radius of a circle?
how many fifths are there in a pound
what map projection is often used to show polar regions
Which organs will be infected first when someone breathes in the TB bacteria?
In a certain plant, yellow leaves are dominant (Y) and red leaves are recessive (y). A plant with genotype Yy and a plant with Yy are crossed. If they have four
In one generation, the frequency of the A allele is 70 percent and the frequency of the a allele is 30 percent. What are the chances of an individual in the nex
What percent of 600 is 84?