このメソッドを使用して、任意の基数の数値を 10 進数に変換しようとしています。
public static int convertToDecimal(String str, int base){
int v = 0;
int total = 0;
int pow = 0;
str = str.toUpperCase();
for(int i = str.length(); i > -1; i--){
char c = str.charAt(i);
if (c >= '0' && c <= '9') {
v = c - '0';
}else if (c >= 'A' && c <= 'Z'){
v = 10 + (c - 'A');
}
total += v * Math.pow(base,pow);
pow++;
}
return total;
}
しかし、配列が境界外の例外を取得することになります。ここで何が間違っていますか?