I'm trying to implement my own substring (fromIndex, toIndex) function using recursion. I have tried several ways of doing this, but there are still errors. Can someone help me with this? This is my code so far:
String s;
RecursiveString(String myS){
s=myS;
}
String subString(int from, int to) {
if(this.s.isEmpty())return "hi";
else if(from==this.s.length()-1)return "";
else if(from==to)return "error";
return this.subString(from+1, to);
}
example:
public static void main(String[] args) {
RecursiveString rs=new RecursiveString("abcesf");
System.out.println(rs.subString(2, 4));
}
output: "error"