Java Program to find the Factorial of a Number using For Loop

preview_player
Показать описание
In this video you will learn to create a Java Program to find the factorial of a number using for loop ( iterative method ).

The factorial of a positive integer n, which is denoted as n!, is the product of all positive integers less than or equal to n.

That is n! = n * (n-1)*(n-2)*....*3*2*1

So 4! = 4 * 3 * 2 * 1 which is equal to 24.

Factorial for the numbers 0 and 1 is 1. That is 0! = 1 and 1! = 1. For negative numbers factorial value doesnt exists.

Java Program to Find the Factorial of a number using Recursion.

Java Program to Find the Factorial of a Large Number

Get the Source Code of this tutorial at

our Social Media Pages

#JavaProgramming #ExampleProgram
Рекомендации по теме
Комментарии
Автор

public class Factorial
{
public static void main(String[] args)
{
// 10 factorial 1*2*3*4*5*6*7*8*9*10
int no=10;
int fact=1;
for(int i=1;i<=10;i++)
fact=fact*i;
{
System.out.println(fact);
}

}

}
this is simple way of factorial

sadhamhussain
Автор

how do I make it 5: (Expected display: "5 x 4 x 3 x 2 x 1 is 120.")??

Randomthings
Автор

Hi, I would like to have the same method but this time with while loop instead of for loop

abdulzariq
Автор

This 'long' data type is maybe a source for errors, isn't it?

stanislavdimitrov
Автор

Mine showed 4! = d! but it said build successful

beng
join shbcf.ru