Regarding String to integer

Sir can you tell me how can i do this recursively i have attempted it two ways
first one is Simple via loop:

public class stint {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	String a="1234";
	char ch[]=a.toCharArray();
	System.out.println(stn(ch,0));
}

public static int stn(char[] c,int si) {
	if(si==c.length) {
		return 0;
	}
	  
	  int sum=stn(c,si+1);
	 
	 System.out.println("------------------------->");  
		 int res=sum*10+c[si]-48;
		  
	
		 
	return res;
}

}

And the second one recursively it was giving the answer reverse manner i.e 4321

public class stint {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	String a="1234";
	char ch[]=a.toCharArray();
	System.out.println(stn(ch,0));
}

public static int stn(char[] c,int si) {
	if(si==c.length) {
		return 0;
	}
	  
	  int sum=stn(c,si+1);
	 
	 System.out.println("------------------------->");  
		 int res=sum*10+c[si]-48;
		  
	
		 
	return res;
}

}

Your recursive code will give correct answer with a little modification. Since you are getting reverse answer, instead of passing 0th index in the beginning, you can pass the last index here:

instead of incrementing by 1 you can decrement by 1 here:

You will also have to change your base case accordingly. You cannot return 0 in the base case here. Think about what should be returned and make changes accordingly. If you still face any problem let me know