Java Reference
In-Depth Information
Thefirstthreevaluesrepresentthehighestfactorialsthatcanbereturnedbythe int -
based, long -based, and double -based factorial() methods. The fourth value
represents the BigInteger equivalent of the highest double factorial.
Noticethatthe double methodfailstoaccuratelyrepresent170!(!isthemathsym-
bol for factorial). Its precision is simply too small. Although the method attempts to
stead of 7998. Rounding is only accurate up to argument 25.0, as the last two output
lines reveal.
Note RSA encryption, BigDecimal , and factorial are practical examples of
BigInteger 's usefulness. However, you can also use BigInteger in unusual
ways.Forexample,myFebruary2006 JavaWorld articletitled“TravelThroughTime
with Java” (
jw-0213-funandgames.html ) , a part of my Java Fun and Games series, used
BigInteger to store an image as a very large integer. The idea was to experiment
with BigInteger methodstolookforimages(possiblybydiscoveringmathematical
never exist. If this craziness appeals to you, check out my article.
The following exercises are designed to test your understanding of Java's language
1. A prime number is a positive integer greater than 1 that is evenly divisible
by 1 and itself. Create a PrimeNumberTest application that determines
message. For example, java PrimeNumberTest 289 should output
themessage 289 is not prime .Asimplewaytocheckforprimality
is to loop from 2 through the square root of the integer argument, and use
the remainder operator in the loop to determine if the argument is divided
Search WWH ::

Custom Search