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 50 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
YES! Correct, THANKS for helping me on my review


amandalm

  • Member
  • Posts: 306
Reply 3 on: Yesterday
Excellent

 

Did you know?

A seasonal flu vaccine is the best way to reduce the chances you will get seasonal influenza and spread it to others.

Did you know?

For about 100 years, scientists thought that peptic ulcers were caused by stress, spicy food, and alcohol. Later, researchers added stomach acid to the list of causes and began treating ulcers with antacids. Now it is known that peptic ulcers are predominantly caused by Helicobacter pylori, a spiral-shaped bacterium that normally exist in the stomach.

Did you know?

Most strokes are caused when blood clots move to a blood vessel in the brain and block blood flow to that area. Thrombolytic therapy can be used to dissolve the clot quickly. If given within 3 hours of the first stroke symptoms, this therapy can help limit stroke damage and disability.

Did you know?

A cataract is a clouding of the eyes' natural lens. As we age, some clouding of the lens may occur. The first sign of a cataract is usually blurry vision. Although glasses and other visual aids may at first help a person with cataracts, surgery may become inevitable. Cataract surgery is very successful in restoring vision, and it is the most frequently performed surgery in the United States.

Did you know?

By definition, when a medication is administered intravenously, its bioavailability is 100%.

For a complete list of videos, visit our video library