Skip to content

Commit fb2c229

Browse files
Kapilrohillauiuxarghya
authored andcommitted
Add java program to calculate Simple Interest
1 parent 60cab76 commit fb2c229

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

src/navs/program.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ export const programsNav = {
1515
pages['java-program-to-add-two-complex-numbers'],
1616
pages['multiply-two-numbers'],
1717
pages['java-program-to-check-Leap-year'],
18+
pages['calculate-simple-interest'],
1819
],
1920
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: Java Program to Calculate Simple interest
3+
shotTitle: Calculate Simple Interest
4+
description: In this program, you'll learn to calculate the simple interest and display final value on screen/terminal
5+
---
6+
import {TipInfo} from '@/components/Tip'
7+
8+
To understand this example, you should have the knowledge of the following Java programming topics:
9+
10+
- [Java Operators](/docs/operators)
11+
- [Java Basic Input and Output](/docs/basic-input-output)
12+
13+
## Calculate Simple Interest
14+
15+
A java program that calculate the simple interest by getting user input for priniple amount, Rate of interest, Time Period.
16+
17+
```java
18+
import java.util.Scanner;
19+
public class simpleInterest {
20+
public static void main(String[] args){
21+
int principleAmount,time;
22+
float interestRatePerAnnum;
23+
// instance of Scanner class
24+
Scanner input = new Scanner(System.in);
25+
// taking user input
26+
System.out.print("Enter the principle amount : ");
27+
principleAmount = input.nextInt();
28+
System.out.print("Enter the rate of interest(per annum): ");
29+
interestRatePerAnnum = input.nextFloat();
30+
System.out.print("Enter the time period(y): ");
31+
time = input.nextInt();
32+
33+
float simpleInterest = (principleAmount * interestRatePerAnnum * time)/100;
34+
35+
System.out.println("Simple Interest: " + simpleInterest);
36+
37+
float totalAmountToReceive = principleAmount + simpleInterest;
38+
System.out.println("Total amount person receive after " + time + " year" + ": " + totalAmountToReceive);
39+
}
40+
}
41+
```
42+
43+
#### Output
44+
45+
```text
46+
Enter the principle amount : 1500
47+
Enter the rate of interest(per annum): 8
48+
Enter the time period(y): 5
49+
Simple Interest: 600.0
50+
Total amount person receive after 5 year: 2100.
51+
```
52+
53+
To Calculate Simple interest ,
54+
```SimpleInterest = (P*R*T)/100```
55+
56+
57+
here, P = principleAmount
58+
R = Rate of interest (%)
59+
T = Time Period (per annum),
60+
61+
We need to take user input for following (P,R,T) and then apply the formulae using ```*,/``` operator. And then, print the output to user's terminal using ```println()``` funciton.
62+
63+
<TipInfo>
64+
65+
Don't know how to take input from the user ? Look at [this examples](/docs/basic-input-output#java-input)
66+
67+
Here two input numbers are taken from user one after another with space in between them which distinguish between two different inputs, this useful behavior is because of the default settings of Scanner called as Delimiter, [learn more here](https://www.javatpoint.com/post/java-scanner-delimiter-method).
68+
69+
</TipInfo>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy