TeachingBee

Program to Calculate EMI in Java

Program to Calculate EMI in Java

In this article, we will see. how to calculate EMI in Java for a loan or financial investment. EMI is a fixed amount paid by a borrower to a lender at a specified date each calendar month. It consists of both the principal amount and the interest on the loan or investment. Calculating EMI is a common financial computation used in the banking and finance industries.

Let’s dive in.

Problem Statement

Given the principal amount (the initial loan amount or investment), the annual interest rate, and the loan tenure (in months), we need to calculate the monthly EMI. The input will include these three parameters, and the output should be the monthly EMI. For Example:

Input:

  • Principal amount: Rs 100,000
  • Annual interest rate: 6% (0.06 as a decimal)
  • Loan tenure (in months): 60 months

Output:

Monthly EMI: Rs 1933.28 (rounded to two decimal places)

Solution

Before we delve into the solutions, let’s briefly discuss the mathematical concept and formula used to calculate EMI.

EMI Formula With Example

EMI Formula: The formula to calculate EMI for a loan or investment is based on the concept of the time value of money. The formula is as follows:

EMI Formula
EMI Formula

Where:

  • EMI is the Equated Monthly Installment.
  • P is the principal amount.
  • r is the monthly interest rate (annual rate divided by 12).
  • t is the total number of monthly installments (loan tenure in months).

Let’s calculate the Equated Monthly Installment (EMI) for a loan with an example. Consider

  • Loan amount: ₹10,000
  • Annual interest rate: 5%
  • Loan tenure: 3 years (36 months)

Here’s how you can calculate the EMI :

  1. Convert the annual interest rate to a monthly rate: Monthly Interest Rate (r) = (Annual Interest Rate / 12) / 100 = (5 / 12) / 100 = 0.004167 (approximately)
  2. Calculate (1 + r)^n: (1 + r)^n = (1 + 0.004167)^36 ≈ 1.169858
  3. Now, use the EMI formula: EMI = [P * r * (1 + r)^n] / [(1 + r)^n – 1] EMI = [₹10,000 * 0.004167 * 1.169858] / [1.169858 – 1]
  4. Calculate the EMI in Indian Rupees: EMI ≈ [₹41.67 * 1,169.858] / [0.169858] EMI ≈ ₹2,900.68 (rounded to the nearest paisa)

So, the Equated Monthly Installment (EMI) for a ₹10,000 loan with a 5% annual interest rate and a loan tenure of 3 years (36 months) is approximately ₹2,900.68. This is the fixed monthly payment you would need to make in Indian Rupees to repay the loan over the specified period.

Algorithm

  • Accept the principal amount, annual interest rate, and loan tenure (in months) as input.
  • Calculate the monthly interest rate (r) by dividing the annual interest rate by 12.
  • Use the EMI formula to calculate the monthly EMI.
  • Display the calculated monthly EMI.

Java Code To Calculate EMI

// EMI Calculator in Java

import java.util.Scanner;

public class CalculateEMI {
    public static void main(String[] args) {
        // Create a Scanner for user input
        Scanner scanner = new Scanner(System.in);

        // Prompt the user to enter the principal amount
        System.out.print("Enter the principal amount: Rs ");
        double principalAmount = scanner.nextDouble();

        // Prompt the user to enter the annual interest rate (in decimal form)
        System.out.print("Enter the annual interest rate (in decimal form): ");
        double annualInterestRate = scanner.nextDouble();

        // Prompt the user to enter the loan tenure (in months)
        System.out.print("Enter the loan tenure (in months): ");
        int loanTenureMonths = scanner.nextInt();

        // Calculate the monthly interest rate (r)
        double monthlyInterestRate = annualInterestRate / 12;

        // Calculate the EMI using the formula
        double emi = (principalAmount * monthlyInterestRate * Math.pow((1 + monthlyInterestRate), loanTenureMonths))
                    / (Math.pow((1 + monthlyInterestRate), loanTenureMonths) - 1);

        // Display the calculated monthly EMI
        System.out.printf("Monthly EMI: Rs %.2f%n", emi);
        
        // Close the scanner
        scanner.close();
    }
}

Output

Enter the principal amount: Rs 100000
Enter the annual interest rate (in decimal form): 0.06
Enter the loan tenure (in months): 60
Monthly EMI: Rs 1933.28

Key Takeaways

  • EMI (Equated Monthly Installment) is a fixed monthly payment made by a borrower to a lender, including both principal and interest components.
  • The EMI calculation formula considers the principal amount, the monthly interest rate, and the loan tenure (in months).

Similar Posts

Add Days To The Current Date in Java

Calculate Area of Hexagon in Java

Calculate Area of a Circle in Java

Reverse A Number In Java

Leap Year Program In Java

Checkout more Java Tutorials here.

I hope You liked the post ?. For more such posts, ? subscribe to our newsletter. Try out our free resume checker service where our Industry Experts will help you by providing resume score based on the key criteria that recruiters and hiring managers are looking for.

FAQ

Is there a way to calculate the total interest paid over the life of a loan using Java?

Can I use these solutions for calculating EMI for other types of loans, such as car loans or mortgages?

90% of Tech Recruiters Judge This In Seconds! 👩‍💻🔍

Don’t let your resume be the weak link. Discover how to make a strong first impression with our free technical resume review!

Related Articles

ascii value in java

Print ASCII Value in Java

In this article we will into the ASCII table in C, exploring its various character sets—from control characters to printable characters, including letters, digits, and special symbols—and demonstrates how to

data hiding in java

Data Hiding In Java

In this article we will discuss data hiding in Java which is an important concept in object-oriented programming. We will cover So let’s get started. What is Data Hiding in

Why Aren’t You Getting Interview Calls? 📞❌

It might just be your resume. Let us pinpoint the problem for free and supercharge your job search. 

Newsletter

Don’t miss out! Subscribe now

Log In