Computer Applications

Write a program to input Principal (p), Rate (r) and Time (t). Calculate and display the amount, which is compounded annually for each year by using the formula:

Simple Interest:

(si) = (prt) / 100

p = p + si

[Hint: The amount after each year is the Principal for the next year]

Java

Java Iterative Stmts

60 Likes

Answer

import java.util.Scanner;

public class KboatCompoundInterest
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter Principal: ");
        double p = in.nextDouble();
        System.out.print("Enter Rate: ");
        double r = in.nextDouble();
        System.out.print("Enter Time: ");
        int t = in.nextInt();
        double amt = p;
        for (int i = 1; i <= t; i++) {
            double interest = (amt * r * 1) / 100.0;
            amt += interest;
            System.out.println("Amount after " + i 
                                + " year = " + amt);
        }
    }
}

Variable Description Table

Program Explanation

Output

Answered By

17 Likes


Related Questions