write a program to check whether a string is a polindrome or not... example "madam"
Answers
Answered by
6
Answer:
ɪᴛ ᴡɪʟʟ ʙᴇ ʏᴏᴜʀ ʜᴇʟᴘ ғᴜʟʟ
Example:
import java.util.Scanner;
class ChkPalindrome
{
public static void main(String args[])
{
String str, rev = "";
Scanner sc = new Scanner(System.in);
System.out.println("Enter a string:");
str = sc.nextLine();
int length = str.length();
for ( int i = length - 1; i >= 0; i-- )
rev = rev + str.charAt(i);
if (str.equals(rev))
System.out.println(str+" is a palindrome");
else
System.out.println(str+" is not a palindrome");
}
}
Program Output:
Enter a string:
radar
radar is a palindrome...
Similar questions