Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. package palindrome;
  2. import java.util.Scanner;
  3. public class Palindrome {
  4.  
  5.    
  6.     public static void main(String[] args) {
  7.         String word = "";
  8.         Scanner scan = new Scanner(System.in);
  9.         word = scan.nextLine();
  10.         String result = isPalindrome(word,0,(word.length()-1));
  11.         System.out.println(result);
  12.      
  13.     }
  14.     public static String isPalindrome(String word,int left, int right)
  15.     {
  16.         String message = "Is not palindrome";
  17.         if(left > right)
  18.         {
  19.             message =  "Is palindrome";
  20.         }
  21.         else if(word.charAt(left) == word.charAt(right) && left < right)
  22.         {
  23.             left++;
  24.             right--;
  25.             message = isPalindrome(word, left, right);
  26.         }
  27.         else if(left == right && word.charAt(left) == word.charAt(right))
  28.         {
  29.             message = "Is palindrome";
  30.         }
  31.        
  32.             return message;
  33.            
  34.        
  35.        
  36.        
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement