public class Palindrome {
public boolean checkPalindrome(String chkString) {
/*
* StringBuilder is Not Thread Safe, but one can do the same, using
* StringBuffer which is Thread Safe, but in places where Thread Safety
* is not needed, prefer using StringBuilder as it will not create
* unnecessary overheads.
*/
StringBuilder sb = new StringBuilder(chkString);
String s_1 = sb.reverse().toString();
// ---- Use equals() if you want the result to be case sensitive
if (!chkString.equalsIgnoreCase(s_1)) {
return false;
}
return true;
}
public static void main(String[] args) {
boolean isE = new Palindrome().checkPalindrome("Aba");
if (isE == true) {
System.out.println("Its a palindrome");
}
else if (isE == false) {
System.out.println("Its not a palidrome");
}
}
}
About Me
- Dark
- B.E.(Computer Science), Android/Java Developer, CCNA, CCNA SECURITY (IINS), CCNP (R&S), 4011 Recognized(NSA & CNSS)U.S.A. , MCSA, MCTS, REDHAT CERTIFIED NETWORK SECURITY ADMINISTRATOR(RH253), AFCEH.
Monday, June 24, 2013
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment