Here you will get program for factorial in java.
We can find factorial of any number by multiplying it with all the numbers below it.
For example, factorial of 4 is 4*3*2*1 = 24.
Program for Factorial in Java
package com; import java.util.Scanner; class Factorial { public static void main(String...s) { int n,fac=1,i; Scanner sc = new Scanner(System.in); System.out.println("Enter a number: "); n = sc.nextInt(); for(i=1;i<=n;i++) fac*=i; System.out.println("\nFactorial = "+fac); sc.close(); } }
Output
Enter a number:
6
Factorial = 720
without package aur util.out se program run ho gayega