Question

Write a method named factorial that accepts an integer n as a parameter and returns the factorial of n, or n!. A factorial of an integer is defined as the product of all integers from 1 through that integer inclusive. For example, the call of factorial(4) should return 1 2 3 4, or 24. The factorial of 0 and 1 are defined to be 1. You may assume that the value passed is non-negative and that its factorial can fit in the range of type int Type your Java solution code here: 2 This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above. 트 | 4 | Indent Sound F/X Highlighting Submit

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public static int factorial(int n) {
    if(n <= 1) {
        return 1;
    } else {
        return n*factorial(n-1);
    }
}
Add a comment
Know the answer?
Add Answer to:
Write a method named factorial that accepts an integer n as a parameter and returns the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT