Java Reference
In-Depth Information
Comprehensive
**5.26
( Palindromic prime ) A palindromic prime is a prime number and also palin-
dromic. For example, 131 is a prime and also a palindromic prime, as are 313 and
757. Write a program that displays the first 100 palindromic prime numbers. Dis-
play 10 numbers per line, separated by exactly one space, as follows:
2 3 5 7 11 101 131 151 181 191
313 353 373 383 727 757 787 797 919 929
...
**5.27
( Emirp ) An emirp (prime spelled backward) is a nonpalindromic prime number
whose reversal is also a prime. For example, 17 is a prime and 71 is a prime, so 17
and 71 are emirps. Write a program that displays the first 100 emirps. Display 10
numbers per line, separated by exactly one space, as follows:
13 17 31 37 71 73 79 97 107 113
149 157 167 179 199 311 337 347 359 389
...
**5.28
( 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
2 p
-
1
p
31
and displays the output as follows:
p 2^p - 1
2 3
3 7
5 31
...
**5.29
( Twin primes ) Twin primes are a pair of prime numbers that differ by 2. For exam-
ple, 3 and 5 are twin primes, 5 and 7 are twin primes, and 11 and 13 are twin
primes. Write a program to find all twin primes less than 1,000. Display the output
as follows:
(3, 5)
(5, 7)
...
**5.30
( Game: craps ) Craps is a popular dice game played in casinos. Write a program to
play a variation of the game, as follows:
Roll two dice. Each die has six faces representing values 1, 2, . . ., and 6, respec-
tively. Check the sum of the two dice. If the sum is 2, 3, or 12 (called craps ), you
lose; if the sum is 7 or 11 (called natural ), you win; if the sum is another value
(i.e., 4, 5, 6, 8, 9, or 10), a point is established. Continue to roll the dice until either
a 7 or the same point value is rolled. If 7 is rolled, you lose. Otherwise, you win.
Your program acts as a single player. Here are some sample runs.
You rolled 5 + 6 = 11
You win
 
 
Search WWH ::




Custom Search