-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompoundInterestCalculator.java
More file actions
30 lines (23 loc) · 1.03 KB
/
compoundInterestCalculator.java
File metadata and controls
30 lines (23 loc) · 1.03 KB
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
import java.util.Scanner;
public class compoundInterestCalculator {
public static void main(String[] args){
double principal;
double rate;
int timesCompounded;
int years;
double amount;
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the principal amount: ");
principal = scanner.nextDouble();
System.out.print("Enter the rate of interest(in %): ");
rate = scanner.nextDouble() / 100;
System.out.print("Enter the number of times compounded per year(usually 1): ");
timesCompounded = scanner.nextInt();
System.out.print("Enter the number of years: ");
years = scanner.nextInt();
amount = principal * Math.pow(1+rate/timesCompounded, timesCompounded*years);
double returns = amount - principal;
System.out.printf("The total amount with the compounded returns is ₹%.2f.\n", amount);
System.out.printf("The total returns you earned on ₹%.2f are ₹%.2f.", principal, returns);
}
}