Java program to find Factorial of a given number

problem statement:- Write a program in java to find a factorial of a given number

 package Loops;
 import java.util.Scanner;
 public class factorial {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        System.out.println("the a is: "+a);
        int result=1;
        for(int i=1;i<=a;i++) {
            result=result*i;
        }
        System.out.println("the result is "+result);
    }
}
output:-
 7
 the a is: 7
 the result is 5040

Comments