Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package palindrome;
- import java.util.Scanner;
- public class Palindrome {
- public static void main(String[] args) {
- String word = "";
- Scanner scan = new Scanner(System.in);
- word = scan.nextLine();
- String result = isPalindrome(word,0,(word.length()-1));
- System.out.println(result);
- }
- public static String isPalindrome(String word,int left, int right)
- {
- String message = "Is not palindrome";
- if(left > right)
- {
- message = "Is palindrome";
- }
- else if(word.charAt(left) == word.charAt(right) && left < right)
- {
- left++;
- right--;
- message = isPalindrome(word, left, right);
- }
- else if(left == right && word.charAt(left) == word.charAt(right))
- {
- message = "Is palindrome";
- }
- return message;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement