import java.util.Scanner;
class FactorialWhile{
public static void main(String args[]){
int fact=1,num,i=1;
System.out.println("Enter the number:");
Scanner in=new Scanner(System.in);
num=in.nextInt();
while(i<=num){
fact=fact*i;
i++;
}
System.out.println("factorial of given number is "+fact);
} }
OUTPUT:
Enter the number:
4
factorial of given number is 24
class FactorialWhile{
public static void main(String args[]){
int fact=1,num,i=1;
System.out.println("Enter the number:");
Scanner in=new Scanner(System.in);
num=in.nextInt();
while(i<=num){
fact=fact*i;
i++;
}
System.out.println("factorial of given number is "+fact);
} }
OUTPUT:
Enter the number:
4
factorial of given number is 24