what is wrong in my code
Move all x recursion code runtime error
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;
}
}
- always try to take a string input using next() method of scanner.
- 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.
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.