Visitar URL original
Update Factorial.java by NeelP2121 · Pull Request #975 · TheAlgorithms/Java · GitHub
The Wayback Machine - https://web.archive.org/web/20201103185252/https://github.com/TheAlgorithms/Java/pull/975
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Factorial.java #975

Open
wants to merge 1 commit into
base: master
from
Open

Conversation

@NeelP2121
Copy link

@NeelP2121 NeelP2121 commented Oct 6, 2019

decreased line of code by 3

@Spikatrix
Copy link
Contributor

@Spikatrix Spikatrix commented Oct 6, 2019

Please test the code before making such changes.

Your modified code is flawed as it will begin recursion decrementing n by 1 in every step and when n becomes negative, the ArithmeticException will be thrown.

Also note that recursion consumes stack space and decreases the readability of the code when compared to iteration. This might result in a Stack Overflow for large values of n. You shouldn't try to reduce the number of lines of code by sacrificing readability.

Copy link
Member

@shellhub shellhub left a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.