Java program to enter the P, T, R, and calculate its Compound Interest
ADVERTISEMENTS
Java program to enter the P, T, R, and calculate its Compound Interest. There are you will learn how to find the Compound Interest through P, T, R in the Java language.
Formula:
CI = P * pow((1 + R / 100), T)
Where:
P = Principal Amount
T = Time
R = Rate
CI = Compound Interest
Let us understand this example through the Java program:
// Java program to enter P, T, R, and calculate Compound Interest
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the principal (amount), time, and rate::\n");
float p = in.nextFloat();
float t = in.nextFloat();
float r = in.nextFloat();
float CI;
// p = principal
// t = time
// r = rate
// SI = compound interest
// Calculate compound interest
CI = (float)(p * (Math.pow((1 + r / 100), t)));
// Output
System.out.println("\nCompound Interest = " + CI);
}
}
Output:
Enter the principal (amount), time, and rate::
5
7
9
Compound Interest = 9.140198