Convert string to integer without using any in | Java program for the above approach ; Function to convert string to integer without using functions ; Initialize a variable ; Iterate till length of the string ; Subtract 48 from the current digit ; Print the answer ; Driver code ; Given string of number ; Function Call
class GFG { public static void convert ( String s ) { int num = 0 ; int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) num = num * 10 + ( ( int ) s . charAt ( i ) - 48 ) ; System . out . print ( num ) ; } public static void main ( String [ ] args ) { String s = "123" ; convert ( s ) ; } }