Results 1 to 1 of 1
Thread: Nested loop problem
 04172011, 03:38 AM #1Member
 Join Date
 Sep 2010
 Location
 Southwest Missouri
 Posts
 97
 Rep Power
 0
Nested loop problem
I am completely lost on this particular program. I am supposed to write a program that finds the monthly payment for 30 years, for principals from
$100,000 through $200,000(with increments of $20,000) and interest rates of
6% through 10% (with increments of 0.5%). The output of the file must be in a table that looks something like this:
Principal 6% 6.5% 7% 7.5% 8% 8.5% 9% 9.5% 10%
100000 600 632 665 699 733 768 804 840 877
120000 719 758 798 839 880 922 965 1009 1053
140000 … … … … … … … … …
160000 … … … … … … … … …
180000 … … … … … … … … …
200000 … … … … … … … … …
The monthly payment on mortgage loan of L dollars, at a rate of interest r is given by:
Monthly payment = [L(1 + r/12)exponent 12N ]/[(1 + r/12)exponent 12N  1]
where N = number of year mortgage (30 years).
The professor gave us this hint:
Java Code:Hint: Use the following idea to compute (1 + r/12)exponent 12N double temp = 1+r/12; double temp1 = 1; for (int i = 1; i<=12*N;i++) { temp1 = temp1*temp; } The final formula now becomes: double mp = (L*(r/12)*temp1)/(temp11);
Java Code:public class ProgrammingProblemTwo { public static void main(String[] args){ //declare variables double r = 0, N = 0, monthlyPayment = 0; double temp1 = 1; double sum; double temp = 1 + r / 12; System.out.println("Principal 6" + "%" + " 6.5" + "%" + " 7" + "%" + " 7.5" + "%" + " 8" + "%" + " 8.5" + "%" + " 9" + "%" + " 9.5" + "%" + " 10" + "%\n"); //create loop to increment principal in dollars, L for(int L = 100000; L <= 200000; L += 20000){ System.out.println(L + "\n"); //create loop to increment interest rate, r for(r = .06; r <= .101; r += .005){ //create (1 + r / 12) exponent 12N formula for (int i = 1; i<=12*N;i++){ temp1 = temp1*temp; monthlyPayment = (L*(r/12)*temp1)/(temp11); } } System.out.println(L + monthlyPayment + "\n"); } } }
Similar Threads

Nested Loop
By sehudson in forum New To JavaReplies: 2Last Post: 03112011, 03:39 AM 
Issue with nested for loop
By sunshine64 in forum New To JavaReplies: 5Last Post: 02032011, 02:45 AM 
Nested For Loop algorithm
By but43r in forum Advanced JavaReplies: 5Last Post: 01112011, 08:52 AM 
can some one help me with nested loop?
By keycoffee in forum New To JavaReplies: 10Last Post: 01252010, 02:49 AM 
Nested For Loop
By yuchuang in forum New To JavaReplies: 1Last Post: 07082007, 01:11 PM
Bookmarks