I am getting run time error in two of my code test case,what is wrong in my code
Palindrome string run time error
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
String str=sc.next();
boolean b=palindrone(str);
System.out.println(b);
// Your Code Here
}
public static boolean palindrone(String str1){
boolean b2=false;
int l=str1.length();
if(l==1||str1==""){
b2=true;
return b2;
}
char ch1=str1.charAt(0);
char ch2=str1.charAt(l-1);
if(ch1==ch2){
boolean ans=palindrone(str1.substring(1,l-1));
return ans;
}
else{
return b2;
}
}
}
@Adhyayan,
https://ide.codingblocks.com/s/202611 Corrected code.
The error was that in Java we use .equals to compare a string with another string not ‘==’.
Instead of str1=="" it should be str1.equals("").
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.