title: How to calculate the sum of geometric series
body: <p>I want to calculate the sum of a geometric series. ie: 1 , 5 , 25 , 125 , etc
  I try to use the math formula to calculate it: a(r^n -1)/(r-1)</p>
  
  <p>My code:</p>
  
  <pre><code>int a = 1;
  int r = 5;
  int deno = r -1;
  int n = 3
  int rn = r^n -1 ;
  
  int total = a * rn / deno;
  </code></pre>
  
  <p>Apparently there is wrong with the code and only some values like the example I give works. I do not know why QAQ</p>
  
  <p>I think the problem is the symbol <code>^</code>
  can anyone explain what <code>^</code> does in java? Appreciate it</p>