Find factorial in JAVA programming



///Md. Alamgir Hossain
///Dept. of Computer Science & Engineering
///Jessore University of Science & Technology

package SolveProblem;

import java.util.Scanner;

public class FactorialNumber {

    public static void main(String[] args) {
        Scanner myScanner=new Scanner(System.in);
        int n;
        System.out.println("Enter a number to calculate its Factorial : ");
        n=myScanner.nextInt();
        if (n==0) {
            System.out.println("Factorial of "+n+ " is : 1");
        }
        else{
            int fact=1;
            for (int i = 1; i <=n; i++) {
                fact=fact*i;
            }
            System.out.println("Factorial of "+n+" is : "+fact);
        }
    }

}

No comments:

Post a Comment