Go the series : https://browncodeit.blogspot.com/p/java-programs.html
Source Code:
- public class FactorialDemo {
- public static void main(String[] args) {
- try (Scanner input = new Scanner(System.in)) {
- int n,i,fact = 1; //variable declaration.
- System.out.println("Enter the number: ");
- n = input.nextInt(); //take input in n variable.
- for(i=n;i>=1;i--) {
- fact = fact*i;
- }
- System.out.println("factorial is :"+fact);
- }
- }
- }
Output:
Enter the number: 5
factorial is :120
Enter the number: 8
factorial is :40320
0 comments:
Post a Comment