Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Loan repayment calculator

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Thanked 0 Times in 0 Posts

    Default Loan repayment calculator

    Hi all.

    I'm having some trouble with a Loan repayment Calculator.

    It seems to be working fine, but it give me answers very different to that of online calculators.

    Any tips greatly appreciated.



    import javax.swing.JOptionPane;
    public class Q1

    public static void main (String [] args)
    String interest = JOptionPane.showInputDialog("Please enter an interest rate");
    double interestRateFirst = Double.parseDouble(interest);
    double interestRate = interestRateFirst / 100;
    String loan = JOptionPane.showInputDialog("Please enter a loan amount in Euro");
    double loanAmount = Double.parseDouble(loan);
    String length = JOptionPane.showInputDialog("Please enter the length of the loan in years");
    double lengthOfLoan = Double.parseDouble(length);

    double monthlyLoanRepayments = (loanAmount*interestRate)/(1-(1/(Math.pow((1+interestRate),(lengthOfLoan*12)))));

    System.out.println("The monthly repayment amount is: " + monthlyLoanRepayments);


    --- Update ---


    Can a mod tag this as solved?

    I just had to change the interest rate to monthly interest.



  2. #2
    Super Moderator
    Join Date
    Jun 2013
    So. Maryland, USA
    My Mood
    Thanked 698 Times in 680 Posts

    Default Re: Loan repayment calculator

    Please post your code in code or highlight tags.

    Your error is in this line:
    double monthlyLoanRepayments = (loanAmount*interestRate)/(1-(1/(Math.pow((1+interestRate),(lengthOfLoan*12)))));
    Compare that to the equation you're using. If you can't find the error, post the equation you're using. OR look at this page for guidance.

Similar Threads

  1. [SOLVED] Need Help Generating Loan Repayment Schedule
    By C++kingKnowledge in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 3rd, 2012, 01:11 PM
  2. Loan Repayment
    By Langolier in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 18th, 2012, 01:29 PM
  3. Loan Payments
    By clarafeb1 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 11th, 2011, 03:36 AM