Find Factorial Of A Number Entered By User | Java Programs

Output:

*** Factorial Program ***

Enter the number: 10
Factorial of 10 is: 3628800

Click Here For Java Online Compiler

Solution:

import java.util.Scanner;

class FactorialInputNumber {

    public static void main(String[] args) {
        int number;
        System.out.println("*** Factorial Program ***" + "\n");
        System.out.print("Enter the number: ");
        Scanner sc = new Scanner(System.in);
        number = sc.nextInt();
        long fact = 1;
        int i = 1;
        while (i <= number) {
            fact = fact * i;
            i++;
        }
        System.out.println("Factorial of " + number + " is: " + fact);
    }
}
Share This :

Related Post



sentiment_satisfied Emoticon