- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Java Program to Calculate the Compound Interest

In this article, we will understand how to calculate the Compound interest. Compound Interest is calculated using the following formula −

Principle*(1+(rate / 100))^time – Principle

**Compound Interest** − The percentage interest charged on principal and accrued interest. Rates are higher compared to Simple Interest.

Below is a demonstration of the same −

**Input**

Suppose our input is −

Enter a Principle number : 100000 Enter Interest rate : 5 Enter a Time period in years : 3

**Output**

The desired output would be −

The Compound Interest is : 15762.50000000001

## Algorithm

Step 1 – START Step 2 – Declare four float values principle, rate, time, compound_interest Step 3 – Read values of principle, rate, time, from the user Step 4 – Perform “principle * (Math.pow((1 + rate / 100), time)) – principle” to calculate the compound interest and store it in a simple_interest variable Step 8 – Display compound_interest Step 10 – STOP

## Example 1

Here, the input is being entered by the user based on a prompt. You can try this example live in ourcoding ground tool .

import java.util.Scanner; public class CompoundInterest { public static void main (String args[]){ double principle, rate, time, compound_interest; System.out.println("Required packages have been imported"); Scanner my_scanner = new Scanner(System.in); System.out.println("A Scanner object has been defined "); System.out.print("Enter a Principle number : "); principle = my_scanner.nextInt(); System.out.print("Enter Interest rate : "); rate = my_scanner.nextInt(); System.out.print("Enter a Time period in years : "); time = my_scanner.nextInt(); compound_interest = principle * (Math.pow((1 + rate / 100), time)) - principle; System.out.println("The Compound Interest is : " + compound_interest); } }

## Output

Required packages have been imported A Scanner object has been defined Enter a Principle number : 100000 Enter Interest rate : 5 Enter a Time period in years : 3 The Compound Interest is : 15762.500000000015

## Example 2

Here, the integer has been previously defined, and its value is accessed and displayed on the console.

public class CompoundInterest{ public static void main (String args[]){ double principle, rate, time, compound_interest; principle = 100000; rate = 5; time = 3; System.out.printf("The Principle amount is %f \nThe interest rate is %f \nThe time period in years is %f " , principle, rate, time); compound_interest = principle * (Math.pow((1 + rate / 100), time)) - principle; System.out.println("\nThe Compound Interest is: " + compound_interest); } }

## Output

The Principle amount is 100000.000000 The interest rate is 5.000000 The time period in years is 3.000000 The Compound Interest is: 15762.50000000001

- Related Articles
- Java Program to calculate Compound Interest
- Java Program to calculate Simple Interest and Compound Interest
- Swift Program to Calculate Compound Interest
- Kotlin Program to Calculate Compound Interest
- Swift Program to Calculate simple interest and compound interest
- Haskell Program to Calculate simple interest and compound interest
- Kotlin Program to calculate Simple Interest and Compound Interest
- C++ Program to Calculate simple interest and compound interest
- Calculate compound interest in JavaScript
- Java Program to Calculate Simple Interest
- How to Calculate Compound Interest using Golang code?
- C Program for the compound interest?
- Python Program for compound interest
- C Program for compound interest?
- Program to find compound interest in C++

Advertisements