Creating a recursive method for Palindrome

前端 未结 21 1988
野的像风
野的像风 2020-12-03 06:28

I am trying to create a Palindrome program using recursion within Java but I am stuck, this is what I have so far:

 public static void main (String[] args){
         


        
21条回答
  •  醉酒成梦
    2020-12-03 07:01

    for you to achieve that, you not only need to know how recursion works but you also need to understand the String method. here is a sample code that I used to achieve it: -

    class PalindromeRecursive {
      public static void main(String[] args) {
    
    
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter a string");
        String input=sc.next();
        System.out.println("is "+ input + "a palindrome : " +  isPalindrome(input));
    
    
      }
    
      public static  boolean isPalindrome(String s)
      {
        int low=0;
        int high=s.length()-1;
        while(low

提交回复
热议问题