November 08, 2018

Find Factorial of a number in java - Consumerfed

/**
 *
 */
package com.hackerearth.basicprograming;

import java.util.Scanner;

/**
 * @author consumerfed
 *
 */
public class FindFactorial {

/**
* @param args
*/
public static void main(String[] args) {


Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long t = System.currentTimeMillis();
int fact = 1;
while(n>=2) {
fact = fact * n;
n--;
}
System.out.println(fact);
System.out.println(System.currentTimeMillis()-t);
}

}

No comments:

Post a Comment

Your feedback may help others !!!

Facebook comments