Re: Program will add but cannot get it to multiply



On Tue, 31 Jan 2006 21:33:17 -0000, shannon <shannondingle@xxxxxxxxxxxxx> wrote:

Thanks, should have realised that.
Replaced number=0 with number=1 and i still get an answer of 0.  I
still need to be able multiple them which I can't get working
Thanks for helping me out with this.

I think Roedy identified the problem. It's going to be a very big number, bigger than can be represented even in a long, let alone an int. You will get overflow, so the answer will not be correct.


The biggest factorial that can be represented in a 64-bit signed integer, such as a Java long, is 20! (20 x 19 x 18 x 17 ... x 2 x 1). The highest positive number you can store is 2^63 or about 9.22 x 10^18 (9.2 billion billion). Your number is much bigger. If you want to calculate that you will have to look into the BigInteger class.

Dan.

--
Daniel Dyer
http://www.dandyer.co.uk
.