Problem:
You have been given a String SS. You need to find and print whether this string is a palindrome or not. If yes, print "YES" (without quotes), else print "NO" (without quotes).
Input Format
The first and only line of input contains the String SS. The String shall consist of lowercase English alphabets only.
Output Format
Print the required answer on a single line.
Constraints 1≤|S|≤1001≤|S|≤100
Note
String SS consists of lowercase English Alphabets only.
SAMPLE INPUT
aba
SAMPLE OUTPUT
YES
Code:
/* IMPORTANT: Multiple classes and nested static classes are supported */
/*
* uncomment this if you want to read input.
//imports for BufferedReader
import java.io.BufferedReader;
import java.io.InputStreamReader;
*/
//import for Scanner and other utility classes
import java.util.*;
class TestClass {
public static void main(String args[] ) throws Exception {
/*
* Read input from stdin and provide input before running
* Use either of these methods for input
//BufferedReader
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
int N = Integer.parseInt(line);
*/
//Scanner
Scanner s = new Scanner(System.in);
String S = s.nextLine();
String result="";
for (int i = S.length()-1; i >=0; i--) {
result=result+S.substring(i,i+1);
}
if(result.equals(S)){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
}
Comments
Post a Comment