1import java.util.Scanner;
2public class RecursivePalindromeJava
3{
4 // to check if string is palindrome using recursion
5 public static boolean checkPalindrome(String str)
6 {
7 if(str.length() == 0 || str.length() == 1)
8 return true;
9 if(str.charAt(0) == str.charAt(str.length() - 1))
10 return checkPalindrome(str.substring(1, str.length() - 1));
11 return false;
12 }
13 public static void main(String[]args)
14 {
15 Scanner sc = new Scanner(System.in);
16 System.out.println("Please enter a string : ");
17 String strInput = sc.nextLine();
18 if(checkPalindrome(strInput))
19 {
20 System.out.println(strInput + " is palindrome");
21 }
22 else
23 {
24 System.out.println(strInput + " not a palindrome");
25 }
26 sc.close();
27 }
28}
1public class StringPalindromeJava
2{
3 public static void isPalindrome(String str)
4 {
5 String strReverse = new StringBuffer(str).reverse().toString();
6 // checking for palindrome
7 if(str.equals(strReverse))
8 {
9 System.out.println(str + " is palindrome string.");
10 }
11 else
12 {
13 System.out.println(str + " is not palindrome string.");
14 }
15 }
16 public static void main(String[] args)
17 {
18 // palindrome java
19 isPalindrome("eye");
20 isPalindrome("rotator");
21 }
22}
1import java.util.*;
2class PalindromeExample2
3{
4 public static void main(String args[])
5 {
6 String original, reverse = ""; // Objects of String class
7 Scanner in = new Scanner(System.in);
8 System.out.println("Enter a string/number to check if it is a palindrome");
9 original = in.nextLine();
10 int length = original.length();
11 for ( int i = length - 1; i >= 0; i-- )
12 reverse = reverse + original.charAt(i);
13 if (original.equals(reverse))
14 System.out.println("Entered string/number is a palindrome.");
15 else
16 System.out.println("Entered string/number isn't a palindrome.");
17 }
18}
1package test
2//The function below checks if a string is a palindrome
3//True = Is a palindrome & False = Not a palindrome
4 public boolean isPalindromString(String text){
5 String reverse = reverse(text);
6 if(text.equals(reverse))
7 {
8 return true;
9 }
10
11 return false;
12 }
13//This function returns the reverse String of its input.
14//Ex. if given "hello", it will return "olleh"
15 public String reverse(String input)
16 {
17 if(input == null || input.isEmpty())
18 {
19 return input;
20 }
21 return input.charAt(input.length()- 1) + reverse(input.substring(0, input.length() - 1));
22 }