title: How do i get my program to count the number of times a method is called?
body: <p>Ok, I am teaching myself java and I am trying to write a recursive method that can count how many times it is called/used. This is my code so far:</p>
  
  <pre><code>public class FinancialCompany
  {
    public static void main(String[] args)
    {
      StdOut.println("Enter your monthly investment: ");
      double money= StdIn.readDouble();
      double total = Sum(money);
      Months();
  
      StdOut.printf("you have reached an amount of $%8.2f", total);
      StdOut.println();
    }
    public static double Sum(double money)
    {
      double total = (money * 0.01) + money;
      if(total &gt;= 1000000)
      {
        return total;
      }
      else
      {  
        total =(money * 0.01) + money;
        return Sum(total);
      }
    }
  
    public static int counter = 0;
  
    public static void Months()
    {
     counter++;
     StdOut.println("It should take about " + counter + " month(s) to reach your goal of $1,000,000");
    }
  
  }
  </code></pre>
  
  <p>This is the output:</p>
  
  <pre><code>Enter your monthly investment: 1000 (I chose 1000)
  It should take about 1 month(s) to reach your goal of $1,000,000
  you have reached an amount of $1007754.58
  </code></pre>
  
  <p>Every time I run this is prints out final amount but I want it to tell me how many months it took to get there but all it prints out is 1 month. Any help will be greatly appreciated!</p>
  
  <p>**</p>
  
  <h2>Completed Code(Thanks to everyone's contributions!)</h2>
  
  <p>**</p>
  
  <pre><code>public class FinancialCompany
  {
  
    public static int counter = 0;
  
    public static void main(String[] args)
    {
      StdOut.println("Enter your monthly investment: ");
      double money= StdIn.readDouble();
      double investment = money;
      double total = Sum(money, investment);    
      StdOut.println("It should take about " + counter + " month(s) to reach your goal of $1,000,000");
    }
    public static double Sum(double money, double investment)
    {
      counter++;
      double total = (money * 0.01) + money;
      if(total &gt;= 1000000)
      {
        return total;
      }
      else
      {  
        return Sum(total + investment ,investment);
      }
    }
  }
  </code></pre>
  
  <ul>
  <li>Zach</li>
  </ul>