KnowledgeBoat Logo

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

ICSE

50 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);
        }
    }
}

Output

BlueJ output of 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]

Answered By

14 Likes


Related Questions