Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-12-2008, 11:54 PM
Member
 
Join Date: Feb 2008
Posts: 1
Froz3n777 is on a distinguished road
Simple Method Question
I have the following code, and I want to make the return statement loop but i'm not sure exactly what i'm doing wrong or if it is even possible.

Code:
import javax.swing.JOptionPane; public class investment { public static void main(String[] args) { String dataString = JOptionPane.showInputDialog( "Enter the investment amount: "); double amount = Integer.parseInt(dataString); String dataString1 = JOptionPane.showInputDialog( "Enter the interest rate: "); double interest = Integer.parseInt(dataString1); String dataString2 = JOptionPane.showInputDialog( "Enter the amount of years: "); int years = Integer.parseInt(dataString2); System.out.println("Years" + " " + "Yearly Amount"); System.out.println("______" + " " + "____________"); System.out.println(investment(amount,interest,years)); } public static double investment(double investmentAmount, double monthlyInterestRate, int years){ double realrate = monthlyInterestRate / 100; double monthlyPayment = investmentAmount * realrate / (1 - 1 / Math.pow(1 + realrate, years * 12)); total = monthlyPayment + investmentAmount; for (i = 1; i <= years; i++) double realtotal = total + monthlyPayment System.out.println(i); return realtotal; } }
I want the output to look something like:
Year 1 - 1093
Year 2 - 1186
Year 3 - 1279
and so forth looping through the amount of years
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-13-2008, 12:25 AM
Member
 
Join Date: Dec 2007
Posts: 30
Leprechaun is on a distinguished road
Once a return statement is executed the method is exited and the code returns to where the method was called.

I would suggest using an array to return your values.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 02-13-2008, 04:39 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,402
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Yes, return statement can't loop several times. What you can do is, store your results in an array and return it. It's easy.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about CAS (compare and swap) method illidian Advanced Java 1 04-04-2008 10:49 PM
Return question in a method. MetalGear New To Java 1 01-13-2008 06:45 AM
Simple append question Rageagainst20 New To Java 0 12-21-2007 01:40 AM
Probably a really simple question... ibanez270dx New To Java 0 11-16-2007 03:27 AM
Simple question of JTable carl AWT / Swing 1 08-07-2007 09:07 AM


All times are GMT +3. The time now is 07:00 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org