Program to print factorial of first n terms given by user in java language.

import java.util.*;
class factorial {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        System.out.print("enter the no. of terms=");
        int n =sc.nextInt();

        for(int i=1; i<=n; i++){
           int fc=1;
          for(int j=i; j>=1; j--){
                fc=fc*j;
            }
             System.out.println("factorial of "+i+" is="+ fc);
            }
    }
}

■》 Output->

enter the no. of terms= 10

factorial of 1 is= 1
factorial of 2 is= 2
factorial of 3 is= 6
factorial of 4 is= 24
factorial of 5 is= 120
factorial of 6 is= 720
factorial of 7 is= 5040
factorial of 8 is= 40320
factorial of 9 is= 362880
factorial of 10 is= 3628800

Comments

Popular posts from this blog

Introduction of java Programming language.

Stack data structure.