CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ | Grades | Students

Assignment #3

Calculate the factorial of a number

Due Date: Monday of Week 2
10 points

This project uses a for loop nested within a while loop to calculate the factorial of a number.

Console

Operation

  • The application prompts the user to enter an integer from 1 to 9.
  • The application displays the factorial of the number entered by the user.
  • The application prompts the user to continue.

Specifications

  • The exclamation point is used to identify a factorial. For example, the factorial of the number n is denoted by n!. Here's how you calculate the factorial of the numbers 1 through 5:
  • 
    1! = 1                   which equals 1
    2! = 1 * 2               which equals 2
    3! = 1 * 2 * 3           which equals 6
    4! = 1 * 2 * 3 * 4       which equals 24
    5! = 1 * 2 * 3 * 4 * 5   which equals 120
     	
  • Use a for loop to calculate the factorial.
  • Assume that the user will enter valid numeric data for the length and width.
  • Use the long type to store the factorial.
  • The application should continue only if the user enters "y" or "Y" to continue.
  • The grading criteria is as follows:

Enhancement

  • Test the application and find the integer for the highest factorial that can be accurately calculated by this application. Then, modify the prompt so it prompts the user for a number from 1 to the highest integer that returns an accurate factorial calculation.
Include in your program the following comments:
  • Name of program
  • Programmer's name
  • Current Date
  • Computer system and compiler you are using
  • Brief description of the program

Compile and run the Java program.

Take a screen capture by hitting simultaneously the keys Alt and Print Screen (Prt Sc) of the output results (console) and paste it in MS Paint. Save it as a gif file.

When you are ready, upload the java program and the gif file by clicking the link below:

Upload Assignment

I cannot grade if I don't get the files and receive your email.