title: Java: About Recursive counting
body: <p>I'm having some problems whit an exercise I found.</p>
  
  <p>I was provided a method, and can't make any changes to it. </p>
  
  <p>Inside said method, I should identify the first repeating digit, beetwen two integers, And return it's position. </p>
  
  <p>For example: 1234 and 4231 results in 1. </p>
  
  <p>And I managed to make it work, </p>
  
  <p>It's just that it doesn't work if I try to use the method more than once, it simply keeps adding to the previous value.</p>
  
  <p>This is my code so far </p>
  
  <pre><code>public static final int BASENUMERACAO = 10;
  public static int indice = 0;
  private static int getLowestIndexWithSameDigit(int a, int b) {
      if (a &lt; 0 || b &lt; 0) {
          throw new IllegalArgumentException("Both numbers should positive " + a + " " + b);
      } else {
          if (a % BASENUMERACAO == b % BASENUMERACAO) {
              return indice;
          } else if (a / BASENUMERACAO != 0 &amp;&amp; b / BASENUMERACAO != 0) {
              indice++;
              return getLowestIndexWithSameDigit(a / BASENUMERACAO, b / BASENUMERACAO);
          } else {
              return -1;
          }
      }
  </code></pre>
  
  <p>I tried passing index, as a local variavel, but it just overrides the curent value, everytime it's called, therefore only returning 0 or -1</p>
  
  <p>Could someone tell me how to I do keep count in a recursive method, or just how do I identify the digit whitout a counter?</p>