Move all X at end

whats wrong in my code
import java.util.*;
public class Main {
static void shift(String str, int i, int count){
if(i >= str.length()){
while(count>0){
count–;
System.out.print(“x”);
return;
}
}
char ch = str.charAt(i);
if(ch == ‘x’){
count++;
}
else{
System.out.print(ch);
}
shift(str, i+1, count);
}
public static void main(String args[]) {
// Your Code Here
Scanner sc = new Scanner(System.in);
String str = sc.next();
shift(str, 0, 0);
}
}

Hi @arsh23
Will you please share your code using coding blocks ide so that it will become easier for me to debug your code and solve your problem more effeciently.

@arsh23
If you see in your code you will find out that if once you find x then again your code is not reconizing that x and thats why your count goest to 1 only and print x only one time. In your ide when you debug your code you will find this abexexdxx try for this input you will be clear.

Let me give you a hint for this problem We follow a recursive approach to solve this problem. At each instance , we check whether the first character is a ‘x’ or not. We recursively obtain the result for the rest of the string i.e. the substring from index 1. If the first character of our current string is an ‘x’ , we concatenate it to the end of our resultant string. Else , we simply place concatenate it back to the front of our resultant string. The second part of the string is the result we obtained recursively.

I hope it will help you if you still face any issue please let me know.