Java Reference
In-Depth Information
Miles Kilometers | Kilometers Miles
1 1.609 | 20 12.430
2 3.218 | 25 15.538
...
9 14.481 | 60 37.290
10 16.090 | 65 40.398
**5.7
( Financial application: compute future tuition ) Suppose that the tuition for a uni-
versity is $10,000 this year and increases 5% every year. In one year, the tuition
will be $10,500. Write a program that computes the tuition in ten years and the
total cost of four years' worth of tuition after the tenth year.
5.8
( Find the highest score ) Write a program that prompts the user to enter the num-
ber of students and each student's name and score, and finally displays the name
of the student with the highest score.
*5.9
( Find the two highest scores ) Write a program that prompts the user to enter the
number of students and each student's name and score, and finally displays the
student with the highest score and the student with the second-highest score.
5.10
( Find numbers divisible by 5 and 6 ) Write a program that displays all the num-
bers from 100 to 1,000, ten per line, that are divisible by 5 and 6. Numbers are
separated by exactly one space.
5.11
( Find numbers divisible by 5 or 6, but not both ) Write a program that displays
all the numbers from 100 to 200, ten per line, that are divisible by 5 or 6, but not
both. Numbers are separated by exactly one space.
5.12
( Find the smallest n such that n 2
12,000 ) Use a while loop to find the smallest
integer n such that n 2 is greater than 12,000.
7
5.13
( Find the largest n such that n 3
12,000 ) Use a while loop to find the largest
integer n such that n 3 is less than 12,000.
Sections 5.8-5.10
*5.14
6
( Compute the greatest common divisor ) Another solution for Listing 5.9 to find
the greatest common divisor of two integers n1 and n2 is as follows: First find d
to be the minimum of n1 and n2 , then check whether d , d-1 , d-2 , ..., 2 , or 1 is
a divisor for both n1 and n2 in this order. The first such common divisor is the
greatest common divisor for n1 and n2 . Write a program that prompts the user to
enter two positive integers and displays the gcd.
*5.15
( Display the ASCII character table ) Write a program that prints the characters in
the ASCII character table from ! to ~ . Display ten characters per line. The ASCII
table is shown in Appendix B. Characters are separated by exactly one space.
*5.16
( Find the factors of an integer ) Write a program that reads an integer and displays
all its smallest factors in increasing order. For example, if the input integer is
120 , the output should be as follows: 2 , 2 , 2 , 3 , 5 .
**5.17
( Display pyramid ) Write a program that prompts the user to enter an integer from
1 to 15 and displays a pyramid, as shown in the following sample run:
Enter the number of lines: 7
1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
6 5 4 3 2 1 2 3 4 5 6
7 6 5 4 3 2 1 2 3 4 5 6 7
 
Search WWH ::




Custom Search