India’s Best Job Seekers and Training Platform › Forums › Java Problems set › Factorial
Tagged: Java
-
Write a program for factorial.
-
import java.util.Scanner;
public class Factorial {
public static void main(String []args){
Scanner Scan=new Scanner(System.in);
System.out.println(“Enter the number”);
int n=Scan.nextInt();
int fac=1;
for(int i=1;i<=n;i++){
fac=fac*i;
}
System.out.println(“Factorial of the given number is : “+fac);
}
}
Log in to reply.