Move all x at end

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String s = sc.next();

   getS(s,0);
   
   

}

public static void getS(String str,int si){
	if(si==str.length()-1){
		
		return ;
	}
	String ros = str.substring(1);
	getS(str,si+1);
	if(str.charAt(si)=='x'){
		str = str.substring(0,si)+str.substring(si+1);
		System.out.println(str+"x");
	}
	
	
	
	if(str.charAt(str.length()-1)=='x'){
		return;
	}
	

}

}

//sir with this code I’m getting my original string and then the correct output in the next line.
please debug it

That’s because you are printing the string again and again. And every time in a new line. Try something like if s.charAt(si) == ‘x’ , then return solve(s.substring(1))+‘x’ else return s

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.