You are viewing a single comment's thread. Return to all comments →
From my HackerRank solutions.
import java.util.Scanner; import java.math.BigInteger; public class Solution { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); scan.close(); System.out.println(factorial(n)); } private static BigInteger factorial(int n) { BigInteger result = BigInteger.ONE; while (n > 1) { result = result.multiply(BigInteger.valueOf(n)); n--; } return result; } }
Let me know if you have any questions.
Seems like cookies are disabled on this browser, please enable them to open this website
Extra Long Factorials
You are viewing a single comment's thread. Return to all comments →
Java solution - passes 100% of test cases
From my HackerRank solutions.
Let me know if you have any questions.