Answers for "best for for palindrome or not in java"

2

palindrome function java

package test
//The function below checks if a string is a palindrome
//True = Is a palindrome & False = Not a palindrome
	public boolean isPalindromString(String text){
    	String reverse = reverse(text);
      	if(text.equals(reverse))
    	{
        	return true;
      	}
      
      	return false;
    }
//This function returns the reverse String of its input.
//Ex. if given "hello", it will return "olleh"
	public String reverse(String input)
    {     
		if(input == null || input.isEmpty())
        {
			return input;
        }
        	return input.charAt(input.length()- 1) + reverse(input.substring(0, input.length() - 1));
    }
Posted by: Guest on June-18-2020
0

is palindrome java

public static boolean checkPalindrome(String str)
{     
 
    int len = str.length();

    for(int i = 0; i < len / 2; i++)  {
        if (str.charAt(i) != str.charAt(len - i - 1))
            return false;
    }
    return true;
}
Posted by: Guest on September-28-2021

Code answers related to "best for for palindrome or not in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language