2) Write a Java code to find the difference between Simple Interest (SI) and Compound
Interest (CI) when - Principal = 150000, Rate of interest = 10% and Time period = 2
years
Answers
Question:-
➡ Write a Java code to find the difference between Simple Interest (SI) and Compound
Interest (CI) when - Principal = 150000, Rate of interest = 10% and Time period = 2 years.
Program:-
class Difference
{
public static void main(String x[])
{
double p=150000, r=10,t=2;
double si=p*r*t/100.0;
double a=p*Math.pow(1+r/100.0,t);
a=a-p; // Now, a = CI earned in 2years.
double diff=si-a;
System.out.println("Difference between simple interest and compound interest is: "+diff);
}
}
Answer:
class Interest
{
public static void main(String ar[])
{
int p=150000;
double r=10; //As it is 10% and 10/100=0.10
int t=2
double si=(p*r*t)/100; //Calculating SI
double ci= p*(Math.pow((1+(r/100)), t) -1) ;
System.out.println("Difference="+(ci-si)) ;
}
}
Explanation:
Note:
The direct formula of ci without finding amount is
CI=P(((1+R/100)^T)-1)