[RESOLVED] different answer
Hello
i was tring to figure out what the result of factorial for 21 using the following code.
java code
Code:
import java.io.*;
/**
*
* @author
*/
public class mywelcome {
public static void main (String[] args) throws IOException
{
BufferedReader userin = new BufferedReader
(new InputStreamReader(System.in));
String inputData;
long N, fact = 1;
System.out.println( "Enter N:" );
inputData = userin.readLine();
N = Integer.parseInt( inputData );
if ( N >= 0 )
{
while ( N > 1 )
{
fact = fact * N;
N = N - 1;
}
System.out.println( "factorial is " + fact );
}
else
{
System.out.println("N must be zero or greater");
}
}
}
when i use the code in the netbeans environment, i get the answer -4249290049419214848
but the following link states the answer should be 51090942171709440000
http://chortle.ccsu.edu/CS151/Notes/...r+greater&N=20
can you guys tell me why the difference?
Re: [RESOLVED] different answer