doubt has been commented in the code
String to integer recursively
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.