Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Factorial

package assesment1;
import java.util.Scanner;
public class factorial {

public static void main(String[] args)


{
int number;
System.out.println("Enter the number: ");
Scanner scanner = new Scanner(System.in);
number = scanner.nextInt();
scanner.close();
long fact = 1;
int i = 1;
while(i<=number)
{
fact = fact * i;
i++;
}
System.out.println("Factorial of "+number+" is: "+fact);
}
}

Output :
Enter the number:
6
Factorial of 6 is: 720

You might also like