The recursive function receives a string and returns a new string so that each couple of chars are the first and the last char of the original. For example:
receives: abcde
returns: aebdc
receives: 1a2b3c
returns: 1ca32b
public class Ex_6 {
public static void main(String[] args) {
String str= "1a2b3c";// 1c a3 2b
System.out.println(insideOut(str));
}
public static String insideOut(String str) {
char ch= str.charAt(0);
String newStr = "";
if (str.length()==1 || str.length()==0 ) //the base case (a returns a)
newStr= str;
else //I tried to build the new string
newStr= ch+str.charAt(str.length()-1) + insideOut(str.substring(1, str.length()-1));
return newStr; //the output was error ("String index out of range: 0")
}