Pages

Footer Pages

Spring Boot

Java String API

Java Conversions

Kotlin Programs

Kotlin Conversions

Java Threads Tutorial

Java 8 Tutorial

Sunday, February 2, 2020

Java Program to Calculate Simple Interest

1. Introduction


In this tutorial, We will learn how to write a java program to find simple interest.

To calculate simple interest, you should know the formula for it.

Simple Interest(SI) = (P × N × R)/100

Here is the meaning for each team in it.

P is Principal amount
R is the rate per annum
N is time in years

Java Program to Calculate Simple Interest


Just for demonstration, We will take an example that a man depositing 10000 rupees into his bank account with an interest of 7% for 5 years. Let us calculate the simple interest that will be given by the bank.

SI = (10000 * 5 * 7) / 100 = 3500

2. Java Program To Find Simple Interest


Now, writing a simple java program to find simple interest using the above formula.

package com.java.w3schools.blog.java.program.to;

import java.util.Scanner;

/**
 * 
 * Java Program to Calculate Simple Interest
 * 
 * @author JavaProgramTo.com
 *
 */
public class SimpleInteretExample {

 public static void main(String[] args) {

  System.out.println("Enter the total principle: ");
  Scanner scanner = new Scanner(System.in);
  float p = scanner.nextFloat();

  System.out.println("Enter the number of years: ");
  float n = scanner.nextFloat();

  System.out.println("Enter the interest: ");
  float r = scanner.nextFloat();

  float si = (p * n * r) / 100;

  System.out.println("Calculated simple interest is : " + si);

 }

}

Output:

Enter the total principle: 10000
Enter the number of years: 5
Enter the interest: 7
Calculated simple interest is : 3500.0

You can try for different inputs when you are running this program every time and see the behavior.

3. Conclusion


In this article, we have seen how to calculate the simple interest for a given principal amount, years and interest. Simple interest formula : (P × N × R)/100

4. References


Wikipedia
investopedia



No comments:

Post a Comment

Please do not add any spam links in the comments section.