I can't seem to find how is the array overflowing. Everything seems to be fine.
class sumofnum {
static int calculate_sum(String num) {
int len, sum = 0, i;
len = num.length();
int[] arr = new int[len - 1];
// fill in array.
for(i = 0; i < len; i++)
arr[i] = Character.getNumericValue(num.charAt(i));
// calculate sum.
for(i = 0; i < len; i++)
sum += arr[i];
return sum;
} // method calculate_sum ends.
I used the above method to try to calculate sum of digits.
Actual output :
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at sumofnum.calculate_sum(sumofnum.java:18)
at sumofnum.main(sumofnum.java:40)