about | help | code help+videos | done | prefs |
Do NOT use recursion for this problem! Write a method that returns the factorial of the non-negative integer input parameter called num. The factorial of 0 is 1 (by definition). The factorial of 1 is also 1. The factorial of num if num is greater than 1 is the product of all the integers from 1 up to and including num. For example, the factorial of 4 is 24 since 1*2*3*4=24. Note that these values can get very big, very fast. Your program must work for values of num in this range: 0<=num<=????? Any value of num greater than 16 will cause the result to be larger than the maximum value that can be stored as an integer. For this reason this method must return a 'long' instead of 'int'. The data type 'long' is exactly like 'int' but can store larger numbers. You may notice that I have repeated some of the test data several times. This was done so you would not simply be able to see all the test data and hard-code a solution. Also, no calculators are allowed for the same reason. capeFactorial(0) → 1 capeFactorial(1) → 1 capeFactorial(2) → 2 ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 290
Copyright Nick Parlante 2017 - privacy