Finding Factorial Using "While Loop" | Java Programs

Output:

*** Factorial Using While lOOp Only ***

Factorial of 5 is: 120

Click Here For Java Online Compiler

Solution:

class FactorialUsingWhileLoop {

    public static void main(String[] args) {

        int factorialOf = 5;
        long fact = 1;
        int i = 1;
        while (i <= factorialOf) {
            fact = fact * i;
            i++;
        }
        System.out.println("*** Factorial Using While lOOp Only ***" + "\n");
        System.out.println("Factorial of " + factorialOf + " is: " + fact);
    }
}
Share This :

Related Post



sentiment_satisfied Emoticon