C Programs Tutorials | IT Developer
IT Developer

Java Programs



Share with a Friend

Introduction to Java

EMI Calculator - Java Program

EMI Formula

    EMI Calculator

Where:

  • P = Loan Amount
  • R = Monthly Interest Rate
  • N = Number of Months

import java.util.Scanner;

 

public class EMICalculator {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

 

        System.out.println("===== EMI CALCULATOR =====");

 

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

        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 annual rate to monthly rate

        double monthlyRate = (annualRate / 12) / 100;

 

        // Convert years to months

        int months = years * 12;

 

        // EMI Formula

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

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

 

        System.out.println("\n------- Result -------");

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

        System.out.printf("Total Payment: %.2f\n", emi * months);

        System.out.printf("Total Interest: %.2f\n", (emi * months - principal));

    }

}

Output

 
OUTPUT :
===== EMI CALCULATOR =====
Enter Loan Amount (P): 500000
Enter Annual Interest Rate (in %): 8
Enter Loan Tenure (in years): 10

------- Result -------
Monthly EMI: 6066.43
Total Payment: 727971.44
Total Interest: 227971.44

Explanation of the Program

Input Section

double principal = sc.nextDouble();

double annualRate = sc.nextDouble();

int years = sc.nextInt();

User provides:

  • Loan amount
  • Annual interest rate
  • Tenure in years

Convert Values

Convert annual rate → monthly rate

double monthlyRate = (annualRate / 12) / 100;

Convert years → months

int months = years * 12;

Apply EMI Formula

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

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

Math.pow(a, b) computes aba^bab.

Display Results

Formatted to 2 decimal places using:

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

Program prints:

  • Monthly EMI
  • Total amount payable
  • Total interest payable