Created
July 2, 2021 15:49
-
-
Save BT-ICD/e1254129fdf41083930c908b9f7c8649 to your computer and use it in GitHub Desktop.
Example to find compound interest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output
Enter principal
1000
Enter rate of interest
10
Enter number of years
2
Amount is 1210.0000000000002