1public class Tester {
2 static int factorial(int n) {
3 if (n == 0)
4 return 1;
5 else
6 return (n * factorial(n - 1));
7 }
8 public static void main(String args[]) {
9 int i, fact = 1;
10 int number = 5;
11 fact = factorial(number);
12 System.out.println(number + "! = " + fact);
13 }
14}
1public class FactorialDemo
2{
3 public static void main(String[] args)
4 {
5 int number = 6, factorial = 1;
6 for(int a = 1; a <= number; a++)
7 {
8 factorial = factorial * a;
9 }
10 System.out.println("Factorial of " + number + " is : " + factorial);
11 }
12}
1public class Factorial {
2
3 public static void main(String[] args) {
4 int num = 6;
5 long factorial = multiplyNumbers(num);
6 System.out.println("Factorial of " + num + " = " + factorial);
7 }
8 public static long multiplyNumbers(int num)
9 {
10 if (num >= 1)
11 return num * multiplyNumbers(num - 1);
12 else
13 return 1;
14 }
15}