{"id":10499,"date":"2015-08-29T00:30:59","date_gmt":"2015-08-29T04:30:59","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/?p=10499"},"modified":"2015-08-24T10:32:08","modified_gmt":"2015-08-24T14:32:08","slug":"factorial-java-computes-an-exact-factorial-n-using-a-biginteger","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=10499","title":{"rendered":"Factorial.java Computes an exact factorial, n!, using a BigInteger"},"content":{"rendered":"<pre>import java.math.BigInteger;\r\n\r\n\/** Computes an exact factorial, using a BigInteger.\r\n\u00a0*\r\n\u00a0*\u00a0 Taken from Core Web Programming from\r\n\u00a0*\u00a0 Prentice Hall and Sun Microsystems Press,\r\n\u00a0*\u00a0 .\r\n\u00a0*\u00a0 \u00a9 2001 Marty Hall and Larry Brown;\r\n\u00a0*\u00a0 may be freely used or adapted.\r\n\u00a0*\/\r\n\r\npublic class Factorial {\r\n\u00a0 public static void main(String[] args) {\r\n\u00a0\u00a0\u00a0 for(int i=1; i&lt;=256; i*=2) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(i + \"!=\" + factorial(i));\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0 }\r\n\r\n\u00a0 public static BigInteger factorial(int n) {\r\n\u00a0\u00a0\u00a0 if (n &lt;= 1) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 return(new BigInteger(\"1\"));\r\n\u00a0\u00a0\u00a0 } else {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 BigInteger bigN = new BigInteger(String.valueOf(n));\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 return(bigN.multiply(factorial(n - 1)));\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0 }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>import java.math.BigInteger; \/** Computes an exact factorial, using a BigInteger. \u00a0* \u00a0*\u00a0 Taken from Core Web Programming from \u00a0*\u00a0 Prentice Hall and Sun Microsystems Press, \u00a0*\u00a0 . \u00a0*\u00a0 \u00a9 2001 Marty Hall and Larry Brown; \u00a0*\u00a0 may be freely used or adapted. \u00a0*\/ public class Factorial { \u00a0 public static void main(String[] args) { \u00a0\u00a0\u00a0 &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=10499\">Continue reading<\/a><\/p>\n","protected":false},"author":130,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1417,1424],"tags":[706,308,285],"class_list":["post-10499","post","type-post","status-publish","format-standard","hentry","category-code-programming-samples--","category-javaj2eej2me","tag-code","tag-java","tag-285","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":26956,"url":"http:\/\/bangla.sitestree.com\/?p=26956","url_meta":{"origin":10499,"position":0},"title":"Factorial.java Computes an exact factorial, n!, using a BigInteger #Programming Code Examples #Java\/J2EE\/J2ME #Basic Java","author":"Author-Check- Article-or-Video","date":"May 6, 2021","format":false,"excerpt":"import java.math.BigInteger; \/** Computes an exact factorial, using a BigInteger. * * Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * . * \u00a9 2001 Marty Hall and Larry Brown; * may be freely used or adapted. *\/ public class Factorial { public static void\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10262,"url":"http:\/\/bangla.sitestree.com\/?p=10262","url_meta":{"origin":10499,"position":1},"title":"ThreadedRSAKey.java Illustrates converting a method in an existing class from a single-threaded method to a multi-threaded method.","author":"","date":"August 26, 2015","format":false,"excerpt":"ThreadedRSAKey.java\u00a0 Illustrates converting a method in an existing class from a single-threaded method to a multi-threaded method. In this example, RSAKey\u00a0 computes an RSA public-private key pair, where the key size has a specified number of digits. As large prime numbers require considerable CPU time, ThreadedRSAKey converts the original computeKey\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":27186,"url":"http:\/\/bangla.sitestree.com\/?p=27186","url_meta":{"origin":10499,"position":2},"title":"ThreadedRSAKey.java Illustrates converting a method in an existing class from a single-threaded method to a multi-threaded method. #Programming Code Examples #Java\/J2EE\/J2ME #Advanced Swing","author":"Author-Check- Article-or-Video","date":"May 13, 2021","format":false,"excerpt":"ThreadedRSAKey.java Illustrates converting a method in an existing class from a single-threaded method to a multi-threaded method. In this example, RSAKey computes an RSA public-private key pair, where the key size has a specified number of digits. As large prime numbers require considerable CPU time, ThreadedRSAKey converts the original computeKey\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26547,"url":"http:\/\/bangla.sitestree.com\/?p=26547","url_meta":{"origin":10499,"position":3},"title":"PrimeNumbers.java  Servlet that processes a request to generate n prime numbers, each with at least m digits. If these results are not complete, it sends a Refresh header instructing the browser to ask for new results a little while later. Uses the Primes #Programming Code Examples #Java\/J2EE\/J2ME #Servlet","author":"Author-Check- Article-or-Video","date":"April 28, 2021","format":false,"excerpt":"PrimeNumbers.java Servlet that processes a request to generate n prime numbers, each with at least m digits. If these results are not complete, it sends a Refresh header instructing the browser to ask for new results a little while later. Uses the Primes, PrimeList, and ServletUtilities classes. package cwp; import\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10173,"url":"http:\/\/bangla.sitestree.com\/?p=10173","url_meta":{"origin":10499,"position":4},"title":"PrimeNumbers.java Servlet that processes a request to generate n prime numbers, each with at least m digits. If these results are not complete, it sends a Refresh header instructing the browser to ask for new results a little while later. Uses the Primes","author":"","date":"August 18, 2015","format":false,"excerpt":"PrimeNumbers.java\u00a0 Servlet that processes a request to generate n prime numbers, each with at least m digits. If these results are not complete, it sends a Refresh header instructing the browser to ask for new results a little while later. Uses the Primes, PrimeList, and ServletUtilities\u00a0 classes. \u00a0 package cwp;\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10448,"url":"http:\/\/bangla.sitestree.com\/?p=10448","url_meta":{"origin":10499,"position":5},"title":"SimplePrimeTag.java Custom tag that outputs a random prime number of a fixed approximate length","author":"","date":"August 28, 2015","format":false,"excerpt":"SimplePrimeTag.java Custom tag that outputs a random prime number of a fixed approximate length package cwp.tags; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; import java.math.*; import cwp.*; \/** Generates a prime of approximately 50 digits. \u00a0*\u00a0 (50 is actually the length of the random number \u00a0*\u00a0 generated -- the first prime\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10499","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/130"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10499"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10499\/revisions"}],"predecessor-version":[{"id":10500,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10499\/revisions\/10500"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10499"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}