Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com When to use Math.pow??

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 10-20-2009, 02:03 PM PM User | #1 easyb New to the CF scene   Join Date: Oct 2009 Posts: 1 Thanks: 0 Thanked 0 Times in 0 Posts When to use Math.pow?? Hi techies, Kindly help me the situation below: //Interest.java /*Mr. Brown invests \$50,000.00 in a savings account yielding 5 percent interest. * Assuming that all interest is left on deposit, write java codes to calculate and print * the amount of money in the account at the end of each year for 10 years. * Use the following formula for determining these amounts: * a=P(1+r)n * Where: * P is the original amount invested i.e. the principal * r is the annual interest rate * n is the number of years * a is the amount on deposit at the end of the nth year * */ public class Interest { public static void main(String[] args) { double P=50000.00; double r=0.05; int n; for(n=1; n<=10; n++); System.out.println("The amount at the end of the first year is:" + P*(1+r)); /*this only prints the result for the first year but I would like to use this result as the principal for the second year and the subsequent for the 3rd year and so on.. **/ } } Any help is appreciated Thanks, Bonny
 10-20-2009, 06:52 PM PM User | #2 mmcnitt New Coder   Join Date: Sep 2009 Posts: 18 Thanks: 1 Thanked 0 Times in 0 Posts i'm not gonna show you in your code so that you can do this but here's your solution i think save more coding and put in a while loop (ex.) Code: ```do System.out.println("the amount of " + n + " if you add 1 is " + ++n); while (n<=1000);``` That displays your n value, will display your amount and increments the n value all in one. and until the while value is true it keeps running whatever is under the do. hope this helps Last edited by mmcnitt; 10-20-2009 at 07:10 PM..
 10-22-2009, 04:53 AM PM User | #3 zero++ New to the CF scene   Join Date: Aug 2009 Posts: 6 Thanks: 3 Thanked 0 Times in 0 Posts Like what mmcnitt said. But first, you should recheck your formula in your code with the given formula
 10-28-2009, 03:02 AM PM User | #4 B101T New to the CF scene   Join Date: Oct 2009 Posts: 5 Thanks: 0 Thanked 0 Times in 0 Posts for(n=1; n<=10; n++); System.out.println("The amount at the end of the first year is:" + P*(1+r)); /*this only prints the result for the first year but I would like to use this result as the principal for the second year and the subsequent for the 3rd year and so on.. **/ Of course it always prints the result of the first year, your never changing the amount, your always printing P*(1+r).. Now, I am not sure about the formula but it looks like you'll probably need a variable to keep track of the current number and add the interest to it before printing: for (n = 1; n <= 10; n++) { P += P*(1+r); System.out.println(P); }

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 12:26 AM.