Compound Interest : Java Program In 5 Simple Ways | Programs
Beginners Programs :

Compound Interest : Java Program In 5 Simple Ways | Programs

How to write a Java program to calculate compound interest? Here we share the code in five different formats to find compound interest program. Using standard values, using recursion, using command line arguments, using while loop, for loop , and using function method etc.

We can even write the following java code to find compound interest in more than 10+ ways as a beginner we share only the basic versions here. If you have any doubts related to the following code, then do leave a a comment here. Here is the complete list of beginners programs and java interview programs. Also check out the core java interview questions.

Table Of Contents :

Sr.NoCompound Interest Program / Methods
1.Using Static Method/standard Method
1.Using Command Line Arguments
1.Using For Loop
1.Using While Loop
1.Using Recursion

  • How to calculate compound interest in math ?

In simple, compound interest is a interest on interest. It’s the result of reinvesting.

  • What’s the formula to find the compound interest ?

Java Program Calculate Compound interest


  • A = ” Ending Amount “
  • P = ” Principal “
  • R =” Interest Rate “
  • N = ” Number of compounding a year “
  • T = ” Total Number Of Years “

Here we go Basic java program with standard values ( Formula based ) to print compound Interest followed by recursion and control statements. At the end of the codes, we embedded an online execution tool where you can execute and print the output for the following programs. Check out the sample simple CI program -1 below with outputs as well.

Sample Code – 1 ( Find CI using standard values )

  • ( Using standard values ) by using the simple/basic math formula you can write any program based on the following example. #Formula based Program#. Also check output and execute the following program at the end of the post.
Output ( Standard Values ) :

Sample Code – 2 ( Using Command Line Arguments )

Output ( Using command line arguments ) : 

Sample Program – 3 ( Using ” For Loop ” )

Here we go another basic and simple method to print CI values, java program to calculate compound interest using For loop. Executing a set of statements repeatedly is known as looping. We have written an article about for loop here. Check out. For loop is the most used loop in java, where it can work out with both while and do while. Check out the program below with outputs.

Output ( Using For Loop ) :

Sample Code – 4 ( Using “While Loop” )

  • Another simple program to print CI values, here we used  a while loop syntax to find the compound interest using while loop.
  • The difference between for loop and while loop is nothing, but as per universal laws, the execution of statement is differ with that code there by all looping will have an different syntax which can impact on execution of statement.
  • The definition of while loop is executing a set of statements repetitively until the condition is true. Check out the program.
Output ( Using While Loop ) :

Sample Code – 5  ( Using “Recursion” )

  • Another method, using recursion. So basically what is recursion, recursion is a method calls itself repeatedly or a method in java that calls itself is called recursive method. Check out the following program using recursion.
Output ( Using Recursion ) :

We are working on to embedded the online execution tool. The online execution tool will help you to learn and practice more programs. You can even execute the above codes and find out how it works in each different case using static, for loop , while loop, and using recursion.

#Java program to find compound interest ends#

Here is the quick reference links : 100+ Beginners programs , Java interview programs and interview question and answers.

More Tutorials :

  1. Do while Java Tutorials With Examples
  2. Java Switch Case Statement Tutorials With Examples
  3. Java Operators With Examples
  4. Java Datatypes And Variables

If you want any custom program, do contact us our expert developers will ready to handle any project or source codes for your project or assignment.