Recursive way to determine whether a string is a palindrome

 

Source

package Test;

 

import java.util. *;

public class test0 {

 

public static boolean func(String str,int start,int size)

{

if(start>=size-1)

return true;

if(str.toCharArray()[start]!=str.toCharArray()[size-1])

return false;

return func(str,start+1,size-1);

}

static void main public (String [] args) {
Scanner Scanner Scan new new = (the System.in);
String S;
System.out.println ( "Please enter the string:");
S = scan.nextLine ();
IF ( FUNC (S, 0, s.length ()))
System.out.println ( "palindromic");
the else
System.out.println ( "not a palindrome");

}

 

}

 

 

 

 

 

Run shot

 

Guess you like

Origin www.cnblogs.com/shenaoyu/p/11582599.html