"Palindrome" is the same sentence that reads and reads the opposite. Like, "Who am I?" the algorithm for detecting palindrome using recursive algorithm is described as follows: a single or Zero-character string is a palindrome. Any other string is a palindrome if the first and last characters is the same, and the string that remains, excepting tho Se characters, is a palindrome.
Palindrome code is as follows:
Package Huiwen;
Import Java.util.Scanner;
public class Huiwen {
public static Boolean ispalindrome (String s,int i,int j) {
if (i > J)
throw new IllegalArgumentException ();
if (i = = j)
return true;
else{
Return (S.charat (i) = = S.charat (j)) && Ispalindrome (s,i+1,j-1);
}
}
public static void Main (string[] args) {
Scanner in=new Scanner (system.in);
String s = in.nextline ();
int i = 0;
Int J = s.length ()-1;
SYSTEM.OUT.PRINTLN (S + "is palindrome?" + Huiwen. Ispalindrome (S, I, j));
}
}
Code:
Use recursive method to determine whether a string is a palindrome (palindrome)