Answers for "java check palindrome with string builder"

0

java check palindrome with string builder

public static boolean isPalindrome(String str){  
    StringBuilder sb=new StringBuilder(str);  
    sb.reverse();  
    String rev=sb.toString();  
    if(str.equals(rev)){  
        return true;  
    }else{  
        return false;  
    }  
}
Posted by: Guest on March-25-2021
1

generate palindrome java

//This function generates a palindrom by recursively reversing a String,
//recursively add it and checks if it's a palindrom

public static String generatePalindrom(String s) {
	return s.equals(reverseString(s)) ? s
				: generatePalindrom(String.valueOf(Integer.parseInt(s) + Integer.parseInt(reverseString(s))));
}

public static String reverseString(String s) {
	return s.length() == 1 ? s : s.charAt(s.length() - 1) + reverseString(s.substring(0, s.length() - 1));
}
Posted by: Guest on March-06-2021

Code answers related to "java check palindrome with string builder"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language