long startTime = System.nanoTime();
BigInteger factorial_minute = doFactorial(50000);
long endTime = System.nanoTime();
String factorial_minute_str = factorial_minute.toString();
System.out.println("Largest n! in one minute = " + factorial_minute);
System.out.println("n! in one minute Amount of Digits: " + factorial_minute_str.length()); // Print the length also
System.out.println("Total execution time: " + (int)((endTime - startTime)/1000000000 + " seconds") );
输出为
编辑,我将其更改为1000000000,但似乎输出仍然是错误的。总执行时间:4秒
答案 0 :(得分:4)
一纳秒是十亿分之一秒,而不是百万分之一秒。向你的除数添加三个零。
(endTime - startTime)/1000000000