This topic contains a solution. Click here to go to the answer

Author Question: Analyze the following recursive method. public static long factorial(int n) {return n * factorial(n - 1); } (Read 42 times)

CORALGRILL2014

  • Hero Member
  • *****
  • Posts: 525

Question 1

What are the base cases in the following recursive method?

public static void xMethod(int n) {
if (n > 0) {
System.out.print(n % 10);
xMethod(n / 10);
}
}

◦ n <= 0
◦ n < 0
◦ n > 0
◦ no base cases

Question 2

Analyze the following recursive method.

public static long factorial(int n) {
return n * factorial(n - 1);
}

◦ Invoking factorial(1) returns 1.
◦ Invoking factorial(0) returns 0.
◦ Invoking factorial(2) returns 2.
◦ Invoking factorial(3) returns 6.
◦ The method runs infinitely and causes a StackOverflowError.


Related Topics

Need homework help now?

Ask unlimited questions for free

Ask a Question
Marked as best answer by CORALGRILL2014 on May 6, 2020

ntsoane kedibone

  • Sr. Member
  • ****
  • Posts: 333
Lorsum iprem. Lorsus sur ipci. Lorsem sur iprem. Lorsum sur ipdi, lorsem sur ipci. Lorsum sur iprium, valum sur ipci et, vala sur ipci. Lorsem sur ipci, lorsa sur iprem. Valus sur ipdi. Lorsus sur iprium nunc, valem sur iprium. Valem sur ipdi. Lorsa sur iprium. Lorsum sur iprium. Valem sur ipdi. Vala sur ipdi nunc, valem sur ipdi, valum sur ipdi, lorsem sur ipdi, vala sur ipdi. Valem sur iprem nunc, lorsa sur iprium. Valum sur ipdi et, lorsus sur ipci. Valem sur iprem. Valem sur ipci. Lorsa sur iprium. Lorsem sur ipci, valus sur iprem. Lorsem sur iprem nunc, valus sur iprium.
Answer Preview
Only 25% of students answer this correctly




CORALGRILL2014

  • Member
  • Posts: 525
Reply 2 on: May 6, 2020
Thanks for the timely response, appreciate it


Hdosisshsbshs

  • Member
  • Posts: 315
Reply 3 on: Yesterday
Great answer, keep it coming :)

 

Did you know?

People often find it difficult to accept the idea that bacteria can be beneficial and improve health. Lactic acid bacteria are good, and when eaten, these bacteria improve health and increase longevity. These bacteria included in foods such as yogurt.

Did you know?

As many as 28% of hospitalized patients requiring mechanical ventilators to help them breathe (for more than 48 hours) will develop ventilator-associated pneumonia. Current therapy involves intravenous antibiotics, but new antibiotics that can be inhaled (and more directly treat the infection) are being developed.

Did you know?

Drug abusers experience the following scenario: The pleasure given by their drug (or drugs) of choice is so strong that it is difficult to eradicate even after years of staying away from the substances involved. Certain triggers may cause a drug abuser to relapse. Research shows that long-term drug abuse results in significant changes in brain function that persist long after an individual stops using drugs. It is most important to realize that the same is true of not just illegal substances but alcohol and tobacco as well.

Did you know?

A serious new warning has been established for pregnant women against taking ACE inhibitors during pregnancy. In the study, the risk of major birth defects in children whose mothers took ACE inhibitors during the first trimester was nearly three times higher than in children whose mothers didn't take ACE inhibitors. Physicians can prescribe alternative medications for pregnant women who have symptoms of high blood pressure.

Did you know?

About 3% of all pregnant women will give birth to twins, which is an increase in rate of nearly 60% since the early 1980s.

For a complete list of videos, visit our video library