Untitled

 avatar
unknown
plain_text
a year ago
795 B
0
Indexable
import java.util.Scanner;

public class CompoundInterest {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter principal amount: ");
        double principal = scanner.nextDouble();

        System.out.print("Enter annual interest rate (in percentage): ");
        double rate = scanner.nextDouble() / 100;

        System.out.print("Enter number of years: ");
        int time = scanner.nextInt();

        System.out.print("Enter number of times interest is compounded per year: ");
        int n = scanner.nextInt();

        double compoundInterest = principal * Math.pow(1 + (rate / n), n * time) - principal;

        System.out.println("Compound Interest: " + compoundInterest);

        scanner.close();
    }
}
Leave a Comment