8. Write a program to calculate compound interest.(JAVA)??
Answers
Answer/ Explanation:
The java program let’s take an example to calculate the compound interest.
Let’s say an amount of $2,000 is deposited into a bank account as a fixed deposit at an annual interest rate of 8%, compounded monthly, the compound interest after 5 years would be:
P = 2000.
R = 8/100 = 0.08 (decimal).
n = 12.
t = 5.
Let’s put these values in the formula.
Compound Interest = 2000 (1 + 0.08 / 12) (12 * 5) – 2000 = $979.69
So, the compound interest after 5 years is $979.69.
Answer:
import java.util.*;
public class Interest{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
float p, r, t, amt;
System.out.print("Enter principle:");
p = sc.nextFloat();
System.out.print("Enter Rate per anum:");
r = sc.nextFloat();
System.out.print("Enter time in years:");
t = sc.nextFloat();
amt = p*Math.pow(1+(r/100), t);
System.out.println("Interest:" + (amt - p));
System.out.println("Amount:" + amt);
}
}