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 41 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
Excellent


cassie_ragen

  • Member
  • Posts: 347
Reply 3 on: Yesterday
:D TYSM

 

Did you know?

The liver is the only organ that has the ability to regenerate itself after certain types of damage. As much as 25% of the liver can be removed, and it will still regenerate back to its original shape and size. However, the liver cannot regenerate after severe damage caused by alcohol.

Did you know?

For pediatric patients, intravenous fluids are the most commonly cited products involved in medication errors that are reported to the USP.

Did you know?

In the United States, congenital cytomegalovirus causes one child to become disabled almost every hour. CMV is the leading preventable viral cause of development disability in newborns. These disabilities include hearing or vision loss, and cerebral palsy.

Did you know?

The use of salicylates dates back 2,500 years to Hippocrates's recommendation of willow bark (from which a salicylate is derived) as an aid to the pains of childbirth. However, overdosage of salicylates can harm body fluids, electrolytes, the CNS, the GI tract, the ears, the lungs, the blood, the liver, and the kidneys and cause coma or death.

Did you know?

When intravenous medications are involved in adverse drug events, their harmful effects may occur more rapidly, and be more severe than errors with oral medications. This is due to the direct administration into the bloodstream.

For a complete list of videos, visit our video library