C Programs Tutorials | IT Developer
IT Developer

Java Programs



Share with a Friend

Operators & Expressions

Java Program: EMI, Interest & Monthly Amortization Calculator

import java.util.Scanner;

 

public class EMICalculator {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

 

        // Taking user input

        System.out.print("Enter Loan Amount: ");

        double principal = sc.nextDouble();

 

        System.out.print("Enter Annual Interest Rate (in %): ");

        double annualRate = sc.nextDouble();

 

        System.out.print("Enter Loan Tenure (in years): ");

        int years = sc.nextInt();

 

        // Convert interest and time

        double monthlyRate = annualRate / (12 * 100);

        int months = years * 12;

 

        // EMI Formula

        double emi = (principal * monthlyRate * Math.pow(1 + monthlyRate, months)) /

                     (Math.pow(1 + monthlyRate, months) - 1);

 

        // Total calculations

        double totalPayment = emi * months;

        double totalInterest = totalPayment - principal;

 

        // Display results

        System.out.printf("\n------- EMI Calculation Result -------\n");

        System.out.printf("Monthly EMI: %.2f\n", emi);

        System.out.printf("Total Interest Payable: %.2f\n", totalInterest);

        System.out.printf("Total Payment (Principal + Interest): %.2f\n", totalPayment);

 

        // Amortization Table Header

        System.out.println("\n------- Monthly Amortization Table -------");

        System.out.printf("%-10s %-12s %-12s %-12s\n",

                "Month", "EMI", "Interest", "Principal");

 

        double balance = principal;

 

        for (int i = 1; i <= months; i++) {

            double interest = balance * monthlyRate;

            double principalPaid = emi - interest;

            balance -= principalPaid;

 

            System.out.printf("%-10d %-12.2f %-12.2f %-12.2f\n",

                    i, emi, interest, principalPaid);

        }

 

        sc.close();

    }

}

Output

INPUT :
Enter Loan Amount: 100000
Enter Annual Interest Rate (in %): 12
Enter Loan Tenure (in years): 1
 
OUTPUT :
------- EMI Calculation Result -------
Monthly EMI: 8884.88
Total Interest Payable: 6618.55
Total Payment (Principal + Interest): 106618.55

------- Monthly Amortization Table -------
Month      EMI          Interest     Principal   
1          8884.88      1000.00      7884.88     
2          8884.88      921.15       7963.73     
3          8884.88      841.51       8043.36     
4          8884.88      761.08       8123.80     
5          8884.88      679.84       8205.04     
6          8884.88      597.79       8287.09     
7          8884.88      514.92       8369.96     
8          8884.88      431.22       8453.66     
9          8884.88      346.68       8538.19     
10         8884.88      261.30       8623.58     
11         8884.88      175.07       8709.81     
12         8884.88      87.97        8796.91     

Explanation

1. EMI Formula

          Java Programs

Where:

  • P = Loan amount
  • r = Monthly interest rate
  • n = Loan tenure in months

2. Calculations

  • Convert annual interest to monthly:

                    r = annualRate / (12×100)

  • Convert years into months:

                     n = years x 12

3. Total Interest & Payment

                Total Payment = EMI x n  

                Total Interest = Total Payment - P

4. Monthly Amortization

For each EMI cycle:

  • Interest part:

             interest = balance x r

  • Principal part:

             principalPaid = EMI - interest

  • Update remaining loan balance:

             balance = balance - principalPaid