0% found this document useful (0 votes)
8 views1 page

Fact

This Java program calculates the factorial of a user-entered number. It uses a Scanner to read the input and a for loop to compute the factorial. The result is then printed to the console.

Uploaded by

98hwkb4rzt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Fact

This Java program calculates the factorial of a user-entered number. It uses a Scanner to read the input and a for loop to compute the factorial. The result is then printed to the console.

Uploaded by

98hwkb4rzt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Program to print the factorial of the entered number

import java.util.*;

import java.io.*;

import java.lang.*;

//Importing Packages

public class Fact //declaring class

{ //opening braces of class

public static void main(String[]args) //declaring main method

{ //opening braces of main method

Scanner pa = new Scanner(System.in); //declaring Scanner class

System.out.println("Enter the number you factorial of");

int n = pa.nextInt(); //Inputing number by user

int f=1;

for(int i=1;i<=n;i++)

{ //opening braces of loop

f=f*i;

} // closing braces of loop

System.out.println("Factorial of "+n+" is "+f); //Printing fatorial

} // closing braces of main method

} // closing braces of class

VARIABLE DATA TYPE FUNCTION


n Integer To store the number entered by the user
f Integer To store and print the factorial
i Integer To execute loop till entered terms

You might also like