Java program to calculate EMIs – In this article, we will detail in on all the possible methods to calculate EMIs on a given loan amount in Java programming.
Suitable examples and sample programs have been given in view of each method discussed. The compiler has also been added so that you can execute the programs easily.
The methods used in the article are as follows:
EMI is the abbreviation for Equated Monthly Installments. As the name itself says, it is a monthly breakdown of the amount that you need to repay your loan accordingly.
EMIs play a significant role in our lives where people pay back their dues in a number of installments, instead of actually paying the whole amount off at one go.
The formula to calculate EMIs is as follows:
EMI = [P x R x (1+R)^N]/[(1+R)^N-1]
P stands for the principal amount.
R is the rate of interest per month [if the interest rate per annum is 11%, then the rate of interest will be 11/(12 x 100)].
N is the number of monthly instalments.
The rate of interest usually depends on the number of instalments that you are opting for and also on the parent organisation.
The various methods used to calculate EMIs in Java programming are as follows:
1.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import java.util.*; class Emi { public static void main(String args[]) { double principal =1200 ; double rate =10 ; double time =1 ; rate=rate/(12*100); time=time*12; double emi= (principal*rate*Math.pow(1+rate,time))/(Math.pow(1+rate,time)-1); System.out.print(" EMI is= "+emi+"\n"); } } |
1 |
EMI is= 105.4990646760119 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import java.util.*; import java.util.Scanner; class Emi { public static void main(String []args) { Scanner a = new Scanner(System.in); double principal, rate, time, emi; System.out.print("Enter principal: "); principal = a.nextFloat(); System.out.print("Enter rate: "); rate = a.nextFloat(); System.out.print("Enter time in year: "); time = a.nextFloat(); rate=rate/(12*100); time=time*12; emi= (principal*rate*Math.pow(1+rate,time))/(Math.pow(1+rate,time)-1); System.out.print("Monthly EMI is= "+emi+"\n"); } } |
1 2 3 4 |
Enter principal: 1200 Enter rate: 20 Enter time in the year: 1 Monthly EMI is= 111.16140707649637 |
1 2 3 4 |
Enter principal: 2000 Enter rate: 20 Enter time in the year: 2 Monthly EMI is= 101.79160528647809 |
1 2 3 4 |
Enter principal: 2000 Enter rate: 20 Enter time in the year: 3 Monthly EMI is= 74.32716671948111 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import java.util.*; import java.util.Scanner; class Emi { public static void main(String []args) { Scanner a = new Scanner(System.in); double principal, rate, time, emi; System.out.print("Enter principal: "); principal = a.nextFloat(); System.out.print("Enter rate: "); rate = a.nextFloat(); System.out.print("Enter time in year: "); time = a.nextFloat(); rate=rate/(12*100); time=time*12; emi= emiCalculation(principal,rate,time); System.out.print("Monthly EMI is= "+emi+"\n"); } static double emiCalculation(double p,double r,double t) { double e= (p*r*Math.pow(1+r,t))/(Math.pow(1+r,t)-1); return e; } } |
1 2 3 4 |
Enter principal: 10000 Enter rate: 25 Enter time in year: 1 Monthly EMI is= 950.4420326390951 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import java.util.*; import java.util.Scanner; class EmiCalculation { double emi; EmiCalculation(double p,double r,double t) { emi= (p*r*Math.pow(1+r,t))/(Math.pow(1+r,t)-1); } } class Emi { public static void main(String []args) { Scanner a = new Scanner(System.in); double principal, rate, time, emi; System.out.print("Enter principal: "); principal = a.nextFloat(); System.out.print("Enter rate: "); rate = a.nextFloat(); System.out.print("Enter time in year: "); time = a.nextFloat(); rate=rate/(12*100); time=time*12; EmiCalculation e= new EmiCalculation(principal,rate,time); System.out.print("EMI is= "+e.emi+"\n"); } } |
1 2 3 4 |
Enter principal: 2500 Enter rate: 1 Enter time in year: 1 EMI is= 209.46352888951324 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import java.util.*; class Emi { public static void main(String args[]) { double principal, rate, time, emi; principal = Double.parseDouble(args[0]); rate = Double.parseDouble(args[1]); time = Double.parseDouble(args[2]); System.out.println(" principal amount is : "+principal); System.out.println("intrest rate is : "+rate); System.out.println("time period is: "+time); rate=rate/(12*100); time=time*12; emi= (principal*rate*Math.pow(1+rate,time))/(Math.pow(1+rate,time)-1); System.out.println("Monthly EMI is= "+emi+"\n"); } } |
1 2 3 4 5 |
>java Emi 50000 10 3 principal amount is : 50000.0 intrest rate is : 10.0 time period is: 3.0 Monthly EMI is= 1613.3593596918788 |