Skip to content

Commit d59544a

Browse files
authored
Merge branch 'main' into main
2 parents da4ae1d + d763c07 commit d59544a

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

src/components/Logos.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function Twitter(props) {
2626
>
2727
<path
2828
fill="currentColor"
29-
d="M23 3a10.9 10.9 0 01-3.14 1.53 4.48 4.48 0 00-7.86 3v1A10.66 10.66 0 013 4s-4 9 5 13a11.64 11.64 0 01-7 2c9 5 20 0 20-11.5a4.5 4.5 0 00-.08-.83A7.72 7.72 0 0023 3z"
29+
d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"
3030
></path>
3131
</svg>
3232
)

src/navs/program.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const programsNav = {
1919
pages['java-program-to-check-divisbility'],
2020
pages['find-quotient-and-reminder'],
2121
pages['calculate-power-of-a-number'],
22+
pages['calculate-compound-interest'],
2223
pages['factorial-in-java'],
2324
],
2425
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: Java program To Calculate Compound Interest
3+
shotTitle: Calculate Compound Interest
4+
description: This code takes the principal amount, annual interest rate (as a percentage), number of years, and compounding frequency (how many times per year the interest is compounded) as input from the user.
5+
---
6+
7+
import { List, ListItemGood } from '@/components/List'
8+
9+
The integer is stored in a variable using `System.in`, and is displayed on the screen using `System.out`.
10+
11+
To understand this example, you should have the knowledge of the following Java programming topics:
12+
13+
- [Java Operators](/docs/operators)
14+
- [Java Basic Input and Output](/docs/basic-input-output)
15+
16+
## to calculate the compound Interest
17+
18+
A java program to calculate compound Interest
19+
20+
21+
## Java Code
22+
23+
```java
24+
import java.util.Scanner;
25+
26+
public class CompoundInterestCalculator {
27+
public static void main(String[] args) {
28+
Scanner scanner = new Scanner(System.in);
29+
30+
// Input principal amount
31+
System.out.print("Enter the principal amount: ");
32+
double principal = scanner.nextDouble();
33+
34+
// Input annual interest rate (as a percentage)
35+
System.out.print("Enter the annual interest rate (as a percentage): ");
36+
double annualRate = scanner.nextDouble();
37+
38+
// Input number of years
39+
System.out.print("Enter the number of years: ");
40+
int years = scanner.nextInt();
41+
42+
// Input number of times interest is compounded per year
43+
System.out.print("Enter the number of times interest is compounded per year: ");
44+
int compoundingFrequency = scanner.nextInt();
45+
46+
// Convert annual rate to decimal and calculate compound interest
47+
double rate = annualRate / 100;
48+
double amount = principal * Math.pow(1 + (rate / compoundingFrequency), compoundingFrequency * years);
49+
50+
// Calculate compound interest
51+
double compoundInterest = amount - principal;
52+
53+
// Display the result
54+
System.out.println("The compound interest after " + years + " years is: " + compoundInterest);
55+
56+
// Close the scanner
57+
scanner.close();
58+
}
59+
}
60+
```
61+
62+
#### Output 1
63+
64+
```text
65+
Enter the principal amount: 5000
66+
Enter the annual interest rate (as a percentage): 5
67+
Enter the number of years: 3
68+
Enter the number of times interest is compounded per year: 4
69+
The compound interest after 3 years is: 797.1955807499652
70+
```
71+
72+
#### Output 2
73+
74+
```text
75+
Enter the principal amount: 10000
76+
Enter the annual interest rate (as a percentage): 3.5
77+
Enter the number of years: 5
78+
Enter the number of times interest is compounded per year: 12
79+
The compound interest after 5 years is: 1938.8365362833173
80+
```

0 commit comments

Comments
 (0)