Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //something wrong with this code
- import java.util.*;
- class Palindrome {
- /* use this method to check whether the string is palindrome word or not
- */
- public static boolean isPalindrome(String word) {
- int n;
- n = word.length();
- Character first = new Character(word.charAt(0));
- Character last = new Character(word.charAt(n-1));
- boolean result;
- if (first.equals(last)){
- if (n == 1 || n == 2 || n == 3){
- result = true;
- } else {
- result = isPalindrome(word.substring(1, n-1));
- }
- } else {
- result = false;
- }
- return result;
- }
- public static void main(String[] args) {
- // declare the necessary variables
- String myWord;
- // declare a Scanner object to read input
- Scanner myScanner = new Scanner(System.in);
- // read input and process them accordingly
- myWord = myScanner.next();
- // simulate the problem
- boolean result = isPalindrome(myWord);
- // output the result
- if (result){
- System.out.println("YES");
- } else{
- System.out.println("NO");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment