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 44 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
Wow, this really help


flexer1n1

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

 

Did you know?

Bacteria have flourished on the earth for over three billion years. They were the first life forms on the planet.

Did you know?

Dogs have been used in studies to detect various cancers in human subjects. They have been trained to sniff breath samples from humans that were collected by having them breathe into special tubes. These people included 55 lung cancer patients, 31 breast cancer patients, and 83 cancer-free patients. The dogs detected 54 of the 55 lung cancer patients as having cancer, detected 28 of the 31 breast cancer patients, and gave only three false-positive results (detecting cancer in people who didn't have it).

Did you know?

According to the FDA, adverse drug events harmed or killed approximately 1,200,000 people in the United States in the year 2015.

Did you know?

Only one in 10 cancer deaths is caused by the primary tumor. The vast majority of cancer mortality is caused by cells breaking away from the main tumor and metastasizing to other parts of the body, such as the brain, bones, or liver.

Did you know?

Adult head lice are gray, about ? inch long, and often have a tiny dot on their backs. A female can lay between 50 and 150 eggs within the several weeks that she is alive. They feed on human blood.

For a complete list of videos, visit our video library