Java - Natural number counting with various bases
<p>I seen this question posted but got stuck and need a bit help to finish. The program is used to count from one number to another using any base the user inputs. </p>

<p>Example: If the user inputs 5 &amp; 10 with a base of 0123456789 it will output 
5 6 7 8 9 10</p>

<p>From what I have so far I can enter 5 and get the next number 6. But 9 to 10 does no work and only gives me 0. When i enter 19 i get 20. When i enter 99 i only get 00. </p>

<p>So what i need is to fix 9 to 10 and 99 to 100      </p>

<pre><code>static String nextNum(String base, String n) {
    int i = n.length() - 1;
    char digit = n.charAt(i)
    int pos = base.indexOf(digit);
    if (pos + 1 &lt; base.length()) {
        n = n.substring(0, i) + base.charAt(pos + 1);
    } else if (i &gt; 0) {
        n = nextNum(base, n.substring(0, i)) + base.charAt(0);
    } else if (pos == base.length() - 1) {
        n = n.substring(0, i) + base.charAt(0) + n.substring(i + 1);
    } else {
        n = "" + base.charAt(1) + base.charAt(0);
    }

    return n;
}

public static void main(String[] args) {
    Scanner input = new Scanner(System.in);

    System.out.print("Please enter base: ");
    String base = input.nextLine();
    System.out.print("Please enter first number: ");
    String n = input.nextLine();
    System.out.print("Please enter second number: ");
    String m = input.nextLine();

    System.out.println(nextNum(base, n));

}
</code></pre>