Check String is palindrome or Not in Java
Check String is Palindrum or Not in Java
1.
class HelloWorld {
public static void main(String[] args) {
String name = "mom";
String revName= "";
for(int i = 0; i<name.length();i++){
revName = name.charAt(i) +revName;
}
if(name.equalsIgnoreCase(revName)){
System.out.println("yes palindrome");
}
else System.out.println("Not palindrome");
}
}
output:yes palindrome
2.
class HelloWorld {
public static void main(String[] args) {
String name = "moma";
String revName= "";
for(int i = 0; i<name.length();i++){
revName = name.charAt(i) +revName;
}
if(name.equalsIgnoreCase(revName)){
System.out.println("yes palindrome");
}
else System.out.println("Not palindrome");
}
}
output:not palindrome
No comments: