In this tutorial you will learn about the Java Program to Calculate Simple Interest and its application with practical example.
Java Program to Calculate Simple Interest
In this tutorial, we will learn to create a Java Program to calculate simple interest using java programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following Java programming concepts:
- Java Operators.
- Basic Input and Output function in Java.
- Class and Object in Java.
- Basic Java programming.
- If-else statements in Java.
- For loop in Java.
What is Simple Interest?
Simple Interest is a method used in Banking, Business, and in economic sectors to calculate the interest charges on loans. Formula to calculate Simple interest
Formula:=>
- Simple Interest = (P × R × T)/100
- Where P = Principal Amount, R = Rate per Annum, T = Time (years)
where:
P is the Principal amount.
R is the rate per annum.
T is time in years.
Algorithm
- Define variables as Principal(P), interest(i), and Time of loans in the year(t).
- Use in the formula.
- Print the Simple Interest.
Java Program to calculate simple interest
In this program, we will find simple interest of given principal rate and time using java programming. We would first declared and initialized the required variables. Next, we will find simple interest. Lets have a look at the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import java.util.Scanner; import java.util.*; public class Simple_interest { public static void main(String args[]) { //decalring varaibles and taking value from user.. float p, r, t, si; Scanner scan = new Scanner(System.in); System.out.print("Enter Principal : "); p = scan.nextFloat(); System.out.print("Enter Rate of interest : "); r = scan.nextFloat(); System.out.print("Enter Time period in year : "); t = scan.nextFloat(); scan.close(); // calculating simple interest si = (p * r * t) / 100; //Printing the result of calculation.. System.out.print("Simple Interest is: " +si); } } |
Output
Simple Interest.
In the above program, we have first declared and initialized a set variables required in the program.
- p= it will hold value of principal.
- r= it will hold value of interest.
- t =it will hold value of time in year.
- si= it will hold value of simple interest.
After declaring variables we initiate values in variables.
now take all the values of Principal rate and time.
after getting all the values we will calculate simple interest using the below formula.
Now print the simple intereset