Java Reference
In-Depth Information
1987 , the month is 9 , and the day is 18 . You may use the GregorianCalendar class
discussed in Programming Exercise 8.5 to simplify coding.)
*10.15
( Geometry: finding the bounding rectangle ) A bounding rectangle is the minimum
rectangle that encloses a set of points in a two-dimensional plane, as shown in
Figure 10.18d. Write a method that returns a bounding rectangle for a set of points
in a two-dimensional plane, as follows:
public static MyRectangle2D getRectangle( double [][] points)
The Rectangle2D class is defined in Exercise 10.13. Write a test program that
prompts the user to enter five points and displays the bounding rectangle's center,
width, and height. Here is a sample run:
Enter five points:
The bounding rectangle's center (5.0, 6.25), width 8.0, height 7.5
1.0 2.5 3 4 5 6 7 8 9 10
Sections 10.12-10.14
*10.16
( Divisible by 2 or 3 ) Find the first ten numbers with 50 decimal digits that are
divisible by 2 or 3 .
*10.17
( Square numbers ) Find the first ten square numbers that are greater than
Long.MAX_VALUE . A square number is a number in the form of
n 2 .
*10.18
( Large prime numbers ) Write a program that finds five prime numbers larger than
Long.MAX_VALUE .
*10.19
( Mersenne prime ) A prime number is called a Mersenne prime if it can be written
in the form for some positive integer p . Write a program that finds all
Mersenne primes with and displays the output as shown below. ( Hint :
You have to use BigInteger to store the number, because it is too big to be
stored in long . Your program may take several hours to run.)
2 p
-
1
p
100
p 2^p - 1
2 3
3 7
5 31
...
*10.20
( Approximate e ) Programming Exercise 4.26 approximates e using the following
series:
1
1
1
2
1
3
1
4
1
i
e
=
1
+
! +
! +
! +
! + c +
!
In order to get better precision, use BigDecimal with 25 digits of precision in the
computation. Write a program that displays the e value for i 100 , 200 , . . . , and
1000 .
=
10.21
( Divisible by 5 or 6 ) Find the first ten numbers (greater than Long.MAX_VALUE )
that are divisible by 5 or 6 .
 
 
Search WWH ::




Custom Search