In this article, we will create a simple interest calculator program in java using formula. This program will take all the required values as input from the user and calculate simple interest.
Below is a formula for calculating simple interest
Simple Interest = (Principal * Time * Rate) / 100
where,
Principal is the amount on which interest will be calculated.
Time is the time period in years, for which interest will be calculated.
Rate is the rate of interest in percentage.
In short, it is written as
S.I. = (P * T * R) / 100
Simple interest calculator program
Below is a java program to calculate simple interest based on user input values of principal, rate and time using the above formula.
import java.util.Scanner; public class SimpleInterestCalculator { public static void main(String[] args) throws IOException { // create scanner object Scanner scanner = new Scanner(System.in); // read values System.out.println("Enter principal"); double principal = scanner.nextDouble(); System.out.println("Enter time in years"); double time = scanner.nextDouble(); System.out.println("Enter rate in percent"); double rate = scanner.nextDouble(); // calculate simple interest with formula double interest = (principal * time * rate)/100; System.out.println("Interest is " + interest); } }
Below is a sample output
Enter principal
1000
Enter time in years
2
Enter rate in percent
10
Interest is 200.0
The program reads the required values such as principal, time and rate as user input, applied simple interest formula using these values and prints the result.
User input is read using Scanner class but you can also use other methods to read user input such as BufferedReader class etc.
Hope the article was useful.