A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward.
Given a string A, print Yes
if it is a palindrome, print No
otherwise.
Constraints
- A will consist at most 50 lower case english letters.
Sample Input
madam
Sample Output
Yes
Solution Implementation
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String A=sc.next();
boolean palindrome = true;
for(int i = 0; i<A.length()/2;i++)
{
if(!A.substring(i,i+1).equals(A.substring(A.length()-i-1,A.length()-i)))
{
palindrome = false;
}
}
if(palindrome){System.out.println("Yes");}
else{System.out.println("No");}
}
}
Copied!