Write Java program to Calculate EMI


The program is a Java code to calculate the monthly EMI (Equated Monthly Installment) based on the principal amount, rate of interest, and time in years entered by the user.

Here are the steps performed in the program:

  • Import the java.util package for accessing the Scanner class to take user input.
  • Declare variables to hold the principal amount, rate of interest, time in years, and EMI.
  • Take input from the user for principal amount, rate of interest, and time in years.
  • Convert the annual rate of interest to the monthly rate by dividing it by 12*100.
  • Convert the time in years to the number of months by multiplying it by 12.
  • Calculate the EMI using the formula: EMI = (principal * rate * (1 + rate) ^ time) / ((1 + rate) ^ time - 1)
  • Display the monthly EMI calculated in step 6.

The formula used to calculate EMI is based on the compound interest formula, and it takes into account the principal amount, rate of interest, and time period to calculate the monthly installment to be paid by the borrower. The formula assumes a constant rate of interest and a constant monthly installment over the entire loan period.

Source Code

import java.util.*;
public class EMI
{
	public static void main(String []args)
	{
		Scanner input = new Scanner(System.in);
		double pri, rate, time, emi;
		System.out.print("Enter the Principal : ");
		pri = input.nextFloat();
		System.out.print("Enter the Rate : ");
		rate = input.nextFloat();
		System.out.print("Enter Time in Year : ");
		time = input.nextFloat();
 
		rate = rate/(12*100);	//one month interest
		time = time*12;		//one month period
		emi = (pri*rate*Math.pow(1+rate,time))/(Math.pow(1+rate,time)-1);
 
		System.out.print("Monthly EMI is : "+emi+"\n");
	}
}

Output

Enter the Principal : 50000
Enter the Rate : 5.0
Enter Time in Year : 12
Monthly EMI is : 462.4452067849273