Java Reference
In-Depth Information
The Rectangle2D class is defined in Programming 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: 1.0 2.5 3 4 5 6 7 8 9 10
The bounding rectangle's center (5.0, 6.25), width 8.0, height 7.5
Section 10.9
*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 . For exam-
ple, 4, 9, and 16 are square numbers. Find an efficient approach to run your
program fast.
*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 writ-
ten in the form 2 p
1 for some positive integer p . Write a program that finds
all Mersenne primes with p
-
100 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.)
p 2^p - 1
2 3
3 7
5 31
...
*10.20
( Approximate e ) Programming Exercise 5.26 approximates e using the following
series:
1
1! +
1
2! +
1
3! +
1
4! + c +
1
i !
e
=
1
+
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 .
Sections 10.10-10.11
**10.22
( Implement the String class ) The String class is provided in the Java library.
Provide your own implementation for the following methods (name the new
class MyString1 ):
public MyString1( char [] chars);
public char charAt( int index);
public int length();
public MyString1 substring( int begin, int end);
public MyString1 toLowerCase();
public boolean equals(MyString1 s);
public static MyString1 valueOf( int i);
 
Search WWH ::




Custom Search