Java Reference
In-Depth Information
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
*4.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
**4.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
*4.20
( Display prime numbers between 2 and 1,000 ) Modify Listing 4.14 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
**4.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:
Number of Years:
Interest Rate Monthly Payment Total Payment
5.000% 188.71 11322.74
5.125% 189.28 11357.13
5.250% 189.85 11391.59
...
7.875% 202.17 12129.97
8.000% 202.76 12165.83
10000
5
For the formula to compute monthly payment, see Listing 2.8, ComputeLoan.java.
 
Search WWH ::




Custom Search