Computer Science, asked by ratnesh12, 1 year ago

write java code to find compound interest

Answers

Answered by AbhijithPrakash
1
Here is your code:
_____________________________________________________________
1public class CompoundInterest {

3    public void calculate(int p, int t, int r, int n) {
4        double amount = p * Math.pow(1 + (r / n), n * t);
5        double interest = amount - p;
6        System.out.println("Compond Interest is " + interest);
7        System.out.println("Amount is " + amount);
8    }
9}

_____________________________________________________________

We take principal (p), time (t), rate of interest (r) and the number of times the interest is compound (n) as inputs. Amount is calculated using the formuale p * ( 1 + r/n )nt. In Java, the Math.pow() function is used to calculate powers. For example, to calculate 32, we use Math.pow(3,2). After finding amount, we find interest by subtracting principal.

Sample Execution :

Input :
p = 3400
t = 3
r = 4
n = 2

Output :
Compond Interest is 2475200.0
Amount is 2478600.0

_____________________________________________________________

Hope this Helps you....

Please mark it as brainliest answer....



ratnesh12: ok
Similar questions