KnowledgeBoat Logo

Computer Applications

Write a program to input the sum. Calculate and display the compound interest in 3 years, when the rates for the successive years are r1%, r2% and r3% respectively.

Hint: [A = P * (1 + (r1 / 100)) * (1 + (r2 / 100)) * (1 + (r3 / 100)) and CI = A - P ]

Java

Java Math Lib Methods

7 Likes

Answer

import java.util.*;

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 interest rate for 1st year: ");
        float r1 = in.nextFloat();
        System.out.print("Enter interest rate for 2nd year: ");
        float r2 = in.nextFloat();
        System.out.print("Enter interest rate for 3rd year: ");
        float r3 = in.nextFloat();
        
        double amt = p * (1 + (r1 / 100)) 
                       * (1 + (r2 / 100)) 
                       * (1 + (r3 / 100));
        double ci = amt - p;
        
        System.out.println("Amount after 3 years: Rs. " + amt);
        System.out.println("Compound Interest: Rs. " + ci);
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of Write a program to input the sum. Calculate and display the compound interest in 3 years, when the rates for the successive years are r1%, r2% and r3% respectively. Hint: [A = P * (1 + (r1 / 100)) * (1 + (r2 / 100)) * (1 + (r3 / 100)) and CI = A - P ]

Answered By

3 Likes


Related Questions