Number 20 factorial on java

Discussion in 'OT Technology' started by morgue, Jun 2, 2006.

1. morgueNew Member

Joined:
Jul 10, 2004
Messages:
8,278
0
what problem would that cause? I think that the range values of of 'int' doesn't cover 20! is that it?

2. PeyompNew Member

Joined:
Jan 11, 2002
Messages:
14,017
0
perl -e '\$myrand = int(rand(25)); @list = (1,2,3,4,5,6,7,8,9,10,0,11,12,13,14,15,16,18,19,20); \$isUnique = map { eval(\$_ == \$myrand)} @list; print "\$myrand is unique: \$isUnique\n" unless \$isUnique; print "\$myrand is not unique: \$isUnique\n" if \$isUnique;'

I don't really know what you're asking, but there's some novel perl code.

3. morgueNew Member

Joined:
Jul 10, 2004
Messages:
8,278
0
suppose java could handle factorial like "3!" which would be 3*2*1=6

What problem would this encounter? "20!"

4. deusexaetheraOT Supporter

Joined:
Jan 27, 2005
Messages:
19,712
0
Integer overflow, most likely.

Joined:
Jan 27, 2005
Messages:
19,712
0

6. morgueNew Member

Joined:
Jul 10, 2004
Messages:
8,278
0
yes, i wanted to know if there's something else other than overflow of an int value... why?

7. deusexaetheraOT Supporter

Joined:
Jan 27, 2005
Messages:
19,712
0
Because asking (and answering) schoolwork questions is generally discouraged on OT; ethics and all that jazz.

8. morgueNew Member

Joined:
Jul 10, 2004
Messages:
8,278
0
well that's dumn :S

9. CyberBulletsI reach to the sky, and call out your name. If I c

Joined:
Nov 13, 2001
Messages:
11,865
0
Location:
Float or Double work? I forget the max sizes, but i believe it's 2^127

10. KingfisherKeepin L's lit

Joined:
Mar 29, 2003
Messages:
4,736
0
Location:
Southern California
look up Fibonacci numbers

private function fib(n as integer)
return fib(n-1) + fib(n-2)

something like that anyways, uses recursion.

11. Penguin ManProtect Your Digital Liberties

Joined:
Apr 27, 2002
Messages:
21,696
0
Location:
Edmonton, AB
I don't know about Java, but in normal languages, float has less range than int does (since some of the 32 bits have to be used for the exponent and decimal places).

Calculating 20! in C, it appears that it does indeed overflow a 32-bit integer (which isn't surprising).

Joined:
Feb 22, 2005
Messages:
47