Move all x recursion code runtime error

what is wrong in my code

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
int l=str.length();
String ans1=moveallx(str);
System.out.println(ans1);

    // Your Code Here
}
public static String moveallx(String str1){
	if(str1.length()==-1){
		String basecase="";
		return basecase;
	}
	char ch=str1.charAt(0);
	String ans=moveallx(str1.substring(1));
	if(ch=='x'){
		ans=ans+'x';
		return ans;
	}
	else{
		ans=ch+ans;
	}
	return ans;
}

}

  1. always try to take a string input using next() method of scanner.
  2. your base condition of recursion is wrong. if string length is 1, it does not matter, its a x or something else.
    thannks

Thank you very much sir

please rate and resolve if satisfied.
thanks

how to rate ,I have never done that

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

@Adhyayan,
What problem are you facing?

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.