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 40 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
:D TYSM


raili21

  • Member
  • Posts: 324
Reply 3 on: Yesterday
YES! Correct, THANKS for helping me on my review

 

Did you know?

Multiple experimental evidences have confirmed that at the molecular level, cancer is caused by lesions in cellular DNA.

Did you know?

The average office desk has 400 times more bacteria on it than a toilet.

Did you know?

Multiple sclerosis is a condition wherein the body's nervous system is weakened by an autoimmune reaction that attacks the myelin sheaths of neurons.

Did you know?

The U.S. Preventive Services Task Force recommends that all women age 65 years of age or older should be screened with bone densitometry.

Did you know?

The average older adult in the United States takes five prescription drugs per day. Half of these drugs contain a sedative. Alcohol should therefore be avoided by most senior citizens because of the dangerous interactions between alcohol and sedatives.

For a complete list of videos, visit our video library