Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Simple Interest
In this article, we will understand how to write a Java program to calculate simple interest. But, before doing it, let's understand how we calculate simple interest mathematically.
The simple interest is a way to determine the amount of interest gained on a principal amount at the specified interest rate for a given time. Unlike compound interest, its principal amount does not change over time.
To calculate Simple Interest, we use the following formula?
Simple Interest (S.I) = Principal * Time * Rate / 100 where, P is the principal amount T is the time R is the rate
Below is an example of the same.
Input : P = 100000
R = 5
T = 2
Output: 1000
Algorithm
We are going to use the following steps to calculate Simple Interest in Java.
Step 1 - Start Step 2 - Declare variables: principal, time, rate, and simple Interest. Step 3 - Assign values to principal, time, and rate. Step 4 - Use the formula: (principal * time * rate) / 100. Step 5 - Store the result in simple Interest. Step 6 - Display all input values and the calculated simple interest. Step 7 - Stop
Java Program to Calculate Simple Interest
Following is a Java program to calculate the simple Interest -
public class SimpleInterest {
public static void main(String[] args) {
double principal = 10000; // Principal amount
double time = 3; // Time in years
double rate = 5.5; // Interest rate in %
double simpleInterest = (principal * time * rate) / 100;
System.out.println("Principal: " + principal);
System.out.println("Time (years): " + time);
System.out.println("Rate of Interest: " + rate);
System.out.println("Simple Interest is: " + simpleInterest);
}
}
On compiling, the above program gives you the following output.
Principal: 10000.0 Time (years): 3.0 Rate of Interest: 5.5 Simple Interest is: 1650.0
Example
Let's see one more example on this -
public class SimpleInterestFloat {
public static void main(String[] args) {
float principal = 12500.50f; // Principal amount in float
float time = 1.5f; // Time in years
float rate = 6.5f; // Interest rate in %
float simpleInterest = (principal * time * rate) / 100;
System.out.println("Principal: " + principal);
System.out.println("Time (years): " + time);
System.out.println("Rate of Interest: " + rate);
System.out.println("Simple Interest is: " + simpleInterest);
}
}
On compiling, the above program gives you the following output.
Principal: 12500.5 Time (years): 1.5 Rate of Interest: 6.5 Simple Interest is: 1218.7987