title: How to write a method to calculate compound interest by the year?
body: <pre><code>public class Balance {
  public static void main(String[] args) {
      System.out.printf("%.2f\n", balance(0.0, 0.0, 0.0));
  }
  /**
   * @param principal
   * @param rate
   * @param years
   * @return
   */
  public static double balance(double principal, double rate, double years) {
      double amount = 0;
      Scanner sc = new Scanner(System.in);
  
      System.out.print("Enter the initial investment amount: ");
      principal = sc.nextDouble();
  
      System.out.print("Enter the interest rate: ");
      rate = sc.nextDouble();
  
      System.out.print("Enter the number of years: ");
      years = sc.nextDouble();
  
      for (int i = 1; i &lt; years; i++) {
          amount = principal * Math.pow(1.0 + rate, years);
          amount += principal;
      }
      return amount - principal;
  
  }
  }
  </code></pre>
  
  <p>My problem is with the printf line that I am using within the main method.  Eclipse wants me to change the method balance from void to Object[].  When I do this I must return a value from balance.  So I guess my question is, how would I return the proper value?  Am I on the right track?  Thank you for your time and constructive criticism. :)</p>
  
  <p>EDIT - Thanks for the help everyone,  much appreciated :)  My math is off.  I end up with 1000 more than I should have. hmmm.</p>
  
  <p>So should I just take a 1000 from amount like so:</p>
  
  <pre><code>return amount - 1000;
  </code></pre>
  
  <p>Or this:</p>
  
  <pre><code>return amount - principal;
  </code></pre>
  
  <p><strong>EDIT</strong> this is what I am going with since it is due tonight.  Thanks to all for the assistance. :)</p>