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
nice
ReplyDeletethnk u
ReplyDeleteusing Iteration for loop in java what would be the program to run
ReplyDeletea) 1!+2!+3!+4!+5!
b) 1/1!+2/2!+3/3!+4/4!+5/5!
c) 1/1!-2/2!+3/3!-4/4!+5/5!
how to create multiple reverse factorial in java ...Example if user input 5 .so 5 of factorial and 4 factorial and 3 ,2,1 . this type give answer..plz help me
ReplyDeleteHow to find the factorial using loop . The output should be in the below form .example 5!
ReplyDeleteO/p - 5*4*3*2*1 = (Result).
Plz tell me how to code this program