Results 1 to 9 of 9

Thread: [RESOLVED] different answer

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Resolved [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?
    Last edited by vb_student; Jun 23rd, 2006 at 06:05 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width