Saturday, 2 July 2016

Write a java program to find the factorial of a given number

import java.util.*;
public class factorial {

    public static void main(String[] args) {
     
        Scanner k=new Scanner(System.in);
        System.out.print("Enter a number: ");
        int n=k.nextInt();
        float s=1;
        for(int i=1;i<=n;i++)
            s=s*i;
        System.out.println("The factorial is: "+s);
    }
 
}

OUTPUT:

Enter a number: 5

The factorial is: 120.0

No comments:

Post a Comment

Popular Posts