Skip to content

Instantly share code, notes, and snippets.

@BT-ICD
Created July 2, 2021 15:49
Show Gist options
  • Save BT-ICD/e1254129fdf41083930c908b9f7c8649 to your computer and use it in GitHub Desktop.
Save BT-ICD/e1254129fdf41083930c908b9f7c8649 to your computer and use it in GitHub Desktop.
Example to find compound interest
/**
* Example: To find compound interest annually
* Learning Reference: https://www.easycalculation.com/compound-interest.php
* */
import java.util.Scanner;
public class CompoundInterestAnnually {
public static void main(String[] args) {
double p, r, amount;
int n;
Scanner sc = new Scanner(System.in);
System.out.println("Enter principal");
p = sc.nextDouble();
System.out.println("Enter rate of interest");
r = sc.nextDouble();
System.out.println("Enter number of years");
n = sc.nextInt();
amount = p*(Math.pow((1+(r/100.0)),n));
System.out.println("Amount is " + amount);
}
}
@BT-ICD
Copy link
Author

BT-ICD commented Jul 2, 2021

Sample output
Enter principal
1000
Enter rate of interest
10
Enter number of years
2
Amount is 1210.0000000000002

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment