Java Reference
In-Depth Information
12. Programming Exercise 7 (Chapter 5) asks you to write a program that
determines whether a positive integer is a prime number. Redo this pro-
gramming exercise by writing a method that takes as input a positive integer
and returns true if the number is a prime number; otherwise, it returns false .
13. Write a program that determines whether a positive integer is a prime
number. If the number is a prime number, then the program also outputs
whether the number is a palindrome. Use the methods developed in
Programming Exercises 11 and 12 of this chapter.
14. A prime number whose reversal is also a prime is called emirp. For example 11,
13, 79, and 359 are emirps. Write a program that outputs the first 100 emirps.
Your program must contain a method that returns true ifanumberisprime;
false otherwise; and another method that returns the reversal of a positive
number. Your program should also prompt the user to enter a positive integer
and then should output whether the positive integer is an emirp.
15. Write a program that takes as input five numbers and outputs the mean
(average) and standard deviation of the numbers. If the numbers are x 1 , x 2 ,
x 3 , x 4 , and x 5 , then the mean is x ¼ (x 1 + x 2 + x 3 + x 4 + x 5 ) / 5 and the
standard deviation is:
7
s
ðx 1 2 þðx 2 2 þðx 3 2 þðx 4 2 þðx 5 2
5
s ¼
:
Your program must contain at least the following method: A method that
calculates and returns the mean and a method that calculates the standard
deviation.
16. You are given a file consisting of students' names in the following form:
lastName firstName middleName . (Note that a student may not have a
middle name.) Write a program that converts each name to the following
form: firstName middleName lastName . Your program must read each
student's entire name in an object and must consist of a method that takes as
input a string, consisting of a student's name, and returns the string con-
sisting of the altered name. Use the string method index to find the index
of , , the method length to find the length of the string, and the method
substring to extract the firstName , middleName , and lastName .
(String methods are described in Chapter 3.)
17. When you borrow money to buy a house, a car, or for some other purpose,
then you typically repay it by making periodic payments. Suppose that the
loan amount is L, r is the interest rate per year, m is the number of payments
in a year, and the loan is for t years. Suppose that i ¼ (r / m) and r is in
decimal. Then the periodic payment is:
L i
1 ð 1 þ iÞ mt :
R ¼
Search WWH ::




Custom Search