Write a recursive method that returns the value of N! (N factorial) using the definition given in this chapter. Explain why you would not normally use recursion to solve this problem.

What will be an ideal response?


```
public int factorial (int num)
{
int result;
if (num == 1)
result = 1;
else
result = num * factorial (num - 1);
return result;
}
```
You would not normally use recursion to solve this problem because it can be done more efficiently and because the recursive solution is no more intuitive than the iterative solution.

Computer Science & Information Technology

You might also like to view...

Which of the following data items are arranged from the smallest to the largest in the data hierarchy.

a. records, characters, fields, bits, files. b. bits, files, fields, records, characters. c. fields, characters, bits, files, records. d. bits, characters, fields, records, files.

Computer Science & Information Technology

Which layout manager is the default for JFrame?

a. FlowLayout b. BorderLayout c. GridLayout d. None of the above

Computer Science & Information Technology

A(n) ________ displays data from an underlying table, query, or SQL statement as specified in the report's Record Source property

A) main report B) bound report C) unbound report D) subreport

Computer Science & Information Technology

Which of the following statements is true of federal laws?

a. They permit employers to monitor instant messages sent and received by employees. b. They authorize public officials to meet in private about matters that affect the state or local area. c. They completely protect individual privacy. d. They forbid customers and employees from accessing data about themselves.

Computer Science & Information Technology