Java Reference
In-Depth Information
*5.18
(
Display four patterns using loops
) Use nested loops that display the following
patterns in four separate programs:
Pattern A Pattern B Pattern C Pattern D
1 1 2 3 4 5 6 1 1 2 3 4 5 6
1 2 1 2 3 4 5 2 1 1 2 3 4 5
1 2 3 1 2 3 4 3 2 1 1 2 3 4
1 2 3 4 1 2 3 4 3 2 1 1 2 3
1 2 3 4 5 1 2 5 4 3 2 1 1 2
1 2 3 4 5 6 1 6 5 4 3 2 1 1
**5.19
(
Display numbers in a pyramid pattern
) Write a nested
for
loop that prints the
following output:
1
1 2 1
1 2 4 2 1
1 2 4 8 4 2 1
1 2 4 8 16 8 4 2 1
1 2 4 8 16 32 16 8 4 2 1
1 2 4 8 16 32 64 32 16 8 4 2 1
1 2 4 8 16 32 64 128 64 32 16 8 4 2 1
*5.20
(
Display prime numbers between 2 and 1,000
) Modify ListingĀ 5.15 to display all
the prime numbers between 2 and 1,000, inclusive. Display eight prime numbers
per line. Numbers are separated by exactly one space.
Comprehensive
**5.21
(
Financial application: compare loans with various interest rates
) Write a pro-
gram that lets the user enter the loan amount and loan period in number of years
and displays the monthly and total payments for each interest rate starting from
5% to 8%, with an increment of 1/8. Here is a sample run:
Loan Amount: 10000
Number of Years: 5
Interest Rate Monthly Payment Total Payment
5.000% 188.71 11322.74
5.125% 189.29 11357.13
5.250% 189.86 11391.59
...
7.875% 202.17 12129.97
8.000% 202.76 12165.84
For the formula to compute monthly payment, see ListingĀ 2.9, ComputeLoan.java.
**5.22
(Financial application: loan amortization schedule)
The monthly payment for a
given loan pays the principal and the interest. The monthly interest is computed
by multiplying the monthly interest rate and the balance (the remaining princi-
pal). The principal paid for the month is therefore the monthly payment minus
the monthly interest. Write a program that lets the user enter the loan amount,
VideoNote
Display loan schedule
Search WWH ::
Custom Search