1// Factorial from 1 to 10 in java
2public class FactorialFrom1To10
3{
4 public static void main(String[] args)
5 {
6 int count;
7 long factorial = 1;
8 System.out.printf("%4s%30s\n", "Number", "Factorials");
9 for(count = 1; count <= 10; count++)
10 {
11 factorial *= count;
12 System.out.printf("%4d%,30d\n", count, factorial);
13 }
14 }
15}
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}