Computer Applications

Write a program by using scanner class to input principal (P), rate (R) and time (T). Calculate and display the amount and compound interest. The program terminates as soon as an alphabet is entered.

Use the formula:

A = P(1 + (R / 100))T
CI = A - P

Java

Input in Java

6 Likes

Answer

import java.util.Scanner;

public class KboatCI
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter an alphabet to exit");
        double p = 0.0, r = 0.0, t = 0.0;
        while (true) {
            System.out.print("Enter principal: ");
            if (in.hasNextDouble())
                p = in.nextDouble();
            else
                break;
            
            System.out.print("Enter rate: ");
            if (in.hasNextDouble())
                r = in.nextDouble();
            else
                break;
                
            System.out.print("Enter time: ");
            if (in.hasNextDouble())
                t = in.nextDouble();
            else
                break;

            double amt = p * Math.pow(1 + (r / 100), t);
            double ci = amt - p;
            System.out.println("Amount = " + amt);
            System.out.println("Compound Interest = " + ci);
        }
    }
}

Variable Description Table

Program Explanation

Output

Answered By

3 Likes


Related Questions