recursive code in java for calculation of money account in a bank -


i want implement recursive code in java calculation of money account in bank after years of investing ... here code

public static double computecapital(double capital, int years, double interestrate) {    if (years == 0) {       return capital;    } else {       double newcapital = capital * math.pow(interestrate,year);       return computecapital(newcapital , years+1 , interestrate);    } } 

is code correct? thanks

   public static double computecapital(double capital, int years, double interestrate) {     if (years == 0) {         return capital;      }     else{     return computecapital(capital, years-1, interestrate)*(1+interestrate);     } } 

Comments

Popular posts from this blog

How to check data type in C++? -

javascript - Is getTimezoneOffset() stable during daylight saving transition? -

sql server - SQL Query returns one result, does not return 0 or NULL result -