What is a factorial in JAVA program?
siddhartharao77:
R u asking the definition of factorial? or program of factorial in java?
Answers
Answered by
3
Factorial is defined as the product of an integer all the integers below it.
Ex: Factorial program in java.
public static void main()
{
int a,b,c=1;
Scanner hell = new Scanner(System.in);
System.out.println("Enter the number :");
a = hell.nextInt();
for(b = a;b>0;b--)
{
c = c * b;
}
System.out.println(c);
}
Output:
Enter the number: 4
4 * 3 * 2 * 1 = 24.
Hope this helps!
Ex: Factorial program in java.
public static void main()
{
int a,b,c=1;
Scanner hell = new Scanner(System.in);
System.out.println("Enter the number :");
a = hell.nextInt();
for(b = a;b>0;b--)
{
c = c * b;
}
System.out.println(c);
}
Output:
Enter the number: 4
4 * 3 * 2 * 1 = 24.
Hope this helps!
Similar questions