Recursive Implementation of atoi ( ) | Recursive Java program to compute atoi ( ) ; Recursive function to compute atoi ( ) ; Base case ( Only one digit ) ; If more than 1 digits , recur for ( n - 1 ) , multiplu result with 10 and add last digit ; Driver code
class GFG { static int myAtoiRecursive ( String str , int n ) { if ( n == 1 ) { return str . charAt ( 0 ) - '0' ; } return ( 10 * myAtoiRecursive ( str , n - 1 ) + str . charAt ( n - 1 ) - '0' ) ; } public static void main ( String [ ] s ) { String str = "112" ; int n = str . length ( ) ; System . out . println ( myAtoiRecursive ( str , n ) ) ; } }