Determining whether a character string to achieve a palindromic sequence recursion

 

 

 

 

// use recursive determines whether a string palindromic sequence 

Import java.util.Scanner;
 public  class Palindrome 
 {    // determines whether the palindromic sequence in parameter that represents a string start and end of 
    public  static  Boolean isPalindrome (S String, int I, int J) { 
          // recursive     
        IF (I || s.length J == () == 0 || s.length () ==. 1 )
             return  to true ;
         IF (s.charAt (I) == S .charAt (J)) 
       { 
           I ++ ; 
           J - ;
            return  isPalindrome (S, I, J);
       } 
        the else return  to false ; 
            } 
            / * return (s.charAt (I) s.charAt == (J)) && isPalindrome (S, I +. 1,. 1-J); * /   
            
    public  static  void main (String [] args) {               
        in Scanner = new new Scanner (the System.in);              
        System.out.println ( "enter a string:" ); 
        string STR = in.nextLine ();
         int I = 0 ;      
         int J = str.length () - . 1 ;          
         IF (isPalindrome (STR, I, J)) 
            System.out.println (STR+ "Palindromic sequence" );   
        the else System.out.println (STR + "is not palindromic sequence" );     
    }   
}             

 

Guess you like

Origin www.cnblogs.com/ywqtro/p/11575452.html