String to integer recursively

doubt has been commented in the code

Hi Vikash,
We took str.charAt(0) - β€˜0’ because the return type is int. Hence this will subtract the ascii value or β€˜0’ that is 48 from the character at 0th position and return us the integer that we want.
If str.charAt(0) is 3, here 3 is a character but str.charAt(0) - β€˜0’ will convert it to integer value 3.

We wrote double because when we are doing calculations Math.pow(10,str.length()-1) we can exceed the range for int and commit a mistake. That’s why we are using double. Also double x = str.charAt(0) - β€˜0’ will give us the int value rather than the ascii value.