# Simple Interest Program in Java

Simple interest program in Java | Simple interest is a quick and easy method of calculating the interest charge on a loan. Simple interest is determined by multiplying the daily interest rate by the principal by the number of days that elapse between payments.

The formula for simple interest is given as,

`Simple Interest = (principal amount × interest rate × time) / 100`

Procedures to write Simple interest program in Java

1) Define class and the main method
2) Declare variables for taking inputs:- principal amount, time, and interest rate
3) import Scanner class of util package to read inputs
4) Read inputs from end-user and store them in the declared variables
5) Calculate simple interest using the formula, and store it in a variable
6) Display the simple interest
7) Close the Scanner class object

## Java program to calculate Simple interest

Program description:- Write a Java program to calculate the simple interest.

``````import java.util.Scanner;

public class SimpleInterest {
public static void main(String[] args) {

// declare variables
double principalAmount = 0.0;
double rate = 0.0;
double time = 0.0;
double interest = 0.0;

// create object of Scanner class
Scanner scan = new Scanner(System.in);

System.out.print("Enter principal amount:: ");
principalAmount = scan.nextDouble();
System.out.print("Enter time (in months):: ");
time = scan.nextDouble();
System.out.print("Enter  the  interest rate (per year):: ");
rate = scan.nextDouble();

// calculate simpleInterest
interest = (principalAmount * rate * time) / 100;

// display result
System.out.println("Simple interest = "+interest);
System.out.println("Total amount to pay = "+
(principalAmount+interest));

// close scan
scan.close();
}
}``````

Output:-

Enter principal amount:: 10000
Enter time (in months):: 60
Enter the interest rate (per year):: 3.9
Simple interest = 23400.0
Total amount to pay = 33400.0

Also see:- Compound interest program in Java

It is good practice to initialize the local variables with their default values at the time of variable declaration. So at the variable declaration time, we initialize those variables with the default value. The variables `principalAmount`, `time`, `rate`, and `interest` are of double data type and 0.0 is the default value of the double data type.

The nextDouble() method of Scanner class is used to read the double data type as input values from the end-user. The nextDouble() method read the string value at the runtime as a floating-point number.

The * and / operators are used for multiplication and division. Later, the result is stored in the interest variable, and it is displayed to the console.

At last, we closed the Scanner class object using `close()` method. It closes the connection between the Java program and the keyboard.

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!
{"ft_lang_label":"__label__en","ft_lang_prob":0.78217727,"math_prob":0.9622884,"size":3298,"snap":"2022-27-2022-33","text_gpt3_token_len":736,"char_repetition_ratio":0.16180936,"word_repetition_ratio":0.0076190475,"special_character_ratio":0.23771983,"punctuation_ratio":0.14119601,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9958433,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-06-28T12:01:36Z\",\"WARC-Record-ID\":\"<urn:uuid:c9bf5e95-556d-4340-a29f-e4f0773f56d1>\",\"Content-Length\":\"139155\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:22d473d6-07f6-4796-81ab-d8c9cbd99840>\",\"WARC-Concurrent-To\":\"<urn:uuid:23fa37a5-572b-495e-9996-36c33aa49345>\",\"WARC-IP-Address\":\"104.21.63.95\",\"WARC-Target-URI\":\"https://www.knowprogram.com/java/simple-interest-program-in-java/\",\"WARC-Payload-Digest\":\"sha1:MSVVEX6WCGNFNQTH657XUQBJKIZI76YW\",\"WARC-Block-Digest\":\"sha1:6ZKOL2I2RX2YSDWLWBIXOISNLNH27HVT\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-27/CC-MAIN-2022-27_segments_1656103516990.28_warc_CC-MAIN-20220628111602-20220628141602-00569.warc.gz\"}"}