More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know.
Q2. Write a Program to check if string is a Colidrome ?
(Colidrome is a word that has n alphabets followed by the reverse of the n alphabets, for ex - mallom)
Ans.
public class Class {
public static void main(String[] args) {
String str = "mallam";
String firstHalf = str.substring(0, str.length() / 2);
String secondHalf = str.substring(str.length() / 2);
if (firstHalf.equals(new StringBuilder(secondHalf).reverse().toString())) {
System.out.println("It's a Colidrome");
} else {
System.out.println("It's not a Colidrome");
}
}
}
Help us improve. Please let us know the company, where you were asked this question :