-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompoundInterest.java
More file actions
35 lines (23 loc) · 953 Bytes
/
CompoundInterest.java
File metadata and controls
35 lines (23 loc) · 953 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.Scanner;
public class CompoundInterest {
public static void main(String[] args) {
// Compound interest calculator
Scanner scanner = new Scanner(System.in);
double principal;
double rate;
int timesCompounded;
int years;
double amount;
System.out.print("Enter the principal amount: ");
principal = scanner.nextDouble();
System.out.print("Enter the interest rate (in %): ");
rate = scanner.nextDouble() / 100;
System.out.print("Enter the number of times compounded per year: ");
timesCompounded = scanner.nextInt();
System.out.print("Enter the number of years: ");
years = scanner.nextInt();
amount=principal * Math.pow(1 + rate / timesCompounded, timesCompounded * years);
System.out.printf("The amount after %d years is $%.2f", years, amount);
scanner.close();
}
}