-->

Hello,This is me!

ITEngineer8995

Professional Coder Coding is my passion

Wednesday, May 20, 2020

Java Program To Calculate Simple Interest

  • May 20, 2020
  • by

Java Program To Calculate Simple Interest

In this Java Program, we calculate Simple Interest.

The interest calculated on the principal amount of the loan is called as simple interest. It is determined by calculating the daily interest rate by the principal by the number of days that elapse between payments.

                                         Simple Interest = (P * R * T) / 100

P = Principal amount
R = Rate per annum
T = Time in years

Let's say a man deposit 2000 INR in a bank account at an interest rate of 6% per annum for 3 years, calculate the simple interest at the end of 3 years.

Simple Interest = 2000 * 6 * 3 / 100 = 360 INR

Logic : sinterest = (p * r * t) / 100

Step 1 : Import java.util.Scanner

Step 2 : Create variables p, r, t, sinterest.

Step 3 : Ask the user to enter the principal by using the Scanner 

Step 4 : Store the user entered principal in the variable named p

Step 5 : Ask the user to enter the rate of interest by using the Scanner 

Step 6 : Store the user entered rate of interest in the variable named r

Step 7 : Ask the user to enter the time period by using the Scanner 

Step 8 : Store the user entered time period in the variable named t

Step 9 : Close the Scanner to avoid memory leak

Step 10 : Calculate the simple interest by using the logic and store it in the variable named sinterest.

Step 11 : Display the result using System.out.print.

Program :

import java.util.Scanner;

public class SimpleInterest
    {
        public static void main(String[] args)
        {
            float p, r, t, sinterest;
            Scanner sc = new Scanner(System.in);
            System.out.print("Enter the Principal:");
            p = sc.nextFloat();
            System.out.print("Enter the Rate of interest:");
            r = sc.nextFloat();
            System.out.print("Enter the Time period:");
            t = sc.nextFloat();
            sc.close();
            sinterest = (p * r * t) / 100;
            System.out.print("Simple Interest is:"+sinterest);
                
        }
    
}

Output:

Enter the Principal : 2000
Enter the Rate of interest : 6
Enter the Time period : 3
Simple Interest is : 360.0

For execution of the same do visit my YouTube Channel:

A blog full of codes of various languages like Java, .net, C, C++ etc with their outputs and some other IT stuff.

0 comments:

Post a Comment

ITEngineer8995
India

SEND ME A MESSAGE

Search This Blog

Powered by Blogger.

Pages