Java - numerical base calculator (ie base 10 to base 5)
<p>I'm trying to make a calculator that calculates and converts numbers from varying bases. Now i believe this has a really small problem but I cant find it for the life of me.Here is the code:</p>

<pre><code>package basecalculator;

import java.util.Scanner;

public class BaseCalculator {

public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

    System.out.println("num?");
    int number = input.nextInt();

    int numLen = String.valueOf(number).length();

    int[] res = new int[numLen];

    toIntArr(number, res);

    for (int i = 0; i &lt; res.length; i++) {
        System.out.print(res[i] + " ");
    }

    System.out.println(toBase10(res));

}

public static void toIntArr(int n, int [] res){
    Stack stack = new Stack();

    while(n &gt; 0) {
        stack.push(n % 10);
        n = n / 10;
    }

    for (int i = 0; !stack.isEmpty(); i++) {
        res[i] = stack.pop();
    }
}

public static int toBase10(int [] res) {
    int sum = 0;

    for (int i = res.length; i &gt;= 0; i--) {
        sum += res[i] * Math.pow(10, i); //here is where it freaks out. 
    }

    return sum;
}
</code></pre>

<p>And this is the error: </p>

<pre><code>run:
num?
456
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at basecalculator.BaseCalculator.toBase10(BaseCalculator.java:49)
at basecalculator.BaseCalculator.main(BaseCalculator.java:28)
4 5 6 Java Result: 1
BUILD SUCCESSFUL (total time: 3 seconds)
</code></pre>

<p>Can anyone identify the problem?</p>
