Java Interest Rate Program

Hey guys!! Welcome to flower brackets blog. You are here to learn java interest rate program. Let us understand what is simple interest with an example.

java interest rate program

What is simple interest?

Simple interest is a method to enumerate interest on invested amount or loan. It is calculated by multiplying principal amount, rate and time.

Also Read – Print Multiplication Tables Of Any Number In Java

Simple Interest = (Principal Amount * Rate * Time) / 100

Example : java interest rate program

Let’s see an example on java interest rate program,

import java.util.Scanner;

public class SimpleInterestInJava
{ 
   public static float SimpleInterest(float valuePrinciple, float valueRate, float valueTime)
   {
      float calInterest = (valuePrinciple * valueRate * valueTime) / 100;
      return calInterest;
   }

   public static void main(String[] args)
   {
      Scanner sc = new Scanner(System.in);
      System.out.println("Simple interest java program");
 
      System.out.println("Please enter principal amount: " );
      float getAmount = sc.nextFloat();
 
      System.out.println("Please enter time(in years): ");
      float getTime = sc.nextFloat();
 
      System.out.println("Please enter rate annually: ");
      float getRate = sc.nextFloat();
 
      float getInterest = SimpleInterest(getAmount, getRate, getTime);
 
      System.out.println("Simple Interest is: " + getInterest);
   }
}

Output:

java interest rate program


Without using method

Now let’s learn java interest rate program without using method,

import java.util.Scanner;

public class SimpleInterestJavaProgram
{
   public static void main(String[] args) 
   {
      float principal, rate, time;
      Scanner sc = new Scanner(System.in);
 
      System.out.print("Enter principal amount : ");
      principal = sc.nextFloat();
 
      System.out.print("Please enter rate annually : ");
      rate = sc.nextFloat();
 
      System.out.print("Please enter time(in years) : ");
      time = sc.nextFloat();
 
      float simpleInterest;
      simpleInterest = (rate * time * principal) / 100;
      System.out.print("The Simple Interest is : " + simpleInterest);
      sc.close();
   }
}

Output:

Enter principal amount : 500000
Please enter rate annually : 2.5
Please enter time(in years) : 3
The Simple Interest is : 37500.0


Compound interest in java

Now let’s learn compound interest in java with an example. First let’s see compound interest formula in java,

// this formula finds compound interest annually

Compound Interest = P (1 + R / 100) r

Where,
P is the principle amount
R is the rate and
T is the time

Here’s the code for compound interest java program,

public class JavaCompoundInterest 
{
   public static void main(String[] args) 
   {
      double principle = 14000, rate = 10.20, time = 5; 
      // finding java compound interest
      double compoundInterest = principle * (Math.pow((1 + rate / 100), time)); 
      System.out.println("Compound Interest in java : " + compoundInterest);
   }
}

Output:

Compound Interest in java : 22752.860716432457


conclusion

So this is all about simple interest java program and compound interest java program. I hope you guys have understood the concept.

You can subscribe to my blog flower brackets if you haven’t already.

Do share this post if you like.

Related Posts