Friday, 19 January 2018

Write a Java Program to Find Factorial of a Number

package com.tutorial4u;

import java.util.Scanner;

public class FactorialNumber {
     public static void main(String[] args) {
           System.out.print("Enter any number to find factorial : ");
           Scanner sc = new Scanner(System.in);
           int num = sc.nextInt();
           int factorial = 1;
           for(int i = 1; i<=num;i++){
               
                factorial = factorial*i;
           }
           System.out.println("Factorial of Enter number "+num+" is : "+factorial);
     }
}




Output : 

Enter any number to find factorial : 5
Factorial of Enter number 5 is : 120


No comments:

Post a Comment

No of Occurrence in Array

package com.tutorial4u; import java.util.HashMap; /************************************************************  No of Occurrence in Array...