import java.util.Scanner;
public class PalindromeString {
public static void main(String[] args) {
System.out.print("Enter any string to check Palindrome : ");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
String reverseString = "";
for(int i = str.length()-1 ; i>=0;i--){
reverseString = reverseString+Character.toString(str.charAt(i));
}
if(reverseString.equals(str)){
System.out.println("Enter string '"+str+"' is
palindrome.");
}else{
System.out.println("Enter string '"+str+"' is
not palindrome.");
}
}
}
Enter
any string to check Palindrome : madam
Enter
string 'madam' is palindrome.
Enter
any string to check Palindrome : Tutorial4u
Enter
string 'Tutorial4u' is not palindrome.
No comments:
Post a Comment