You can view/download the program by clicking here.
While making this program, I realized some interesting things about doing factorials in Java. The main problem is that, if you only use the int data type, the highest number the program can successfully compute the factorial of is 12. Anything past that is computed either negative, incorrect, or just plain old 0.
When I changed everything to long, it became possible to calculate factorials up through 20. Anything past that continues to be calculated incorrectly. For example, inputting 21 causes this to happen:
No comments:
Post a Comment