Java program to find the factorial of the given number

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Hello Sir,
i like your videos alot. Your explanations is very simple to understand. I love the way you teach.
I have tried to find the factorial using for loop. please check it and suggest it, is it ok.
thanks

import java.util.Scanner;

public class FactorialOfNumber
{

/*Program to find factorial of a number.*/

public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter number");
int num = sc.nextInt();
sc.close();
int factorial=1;
for (int i = 1; i<=num; i++)
{
factorial = factorial * i;
}
System.out.println("The factorial of "+num+" is "+factorial+"");


}

}

sunnygupta