Java Program to Check the String is Palindrome(using StringBuffer)

In this blog we will learn how to check the string whether it is a palindrome or not using string buffer.


Implementation:

import java.util.Scanner;
public class Task_Palindrome1 
private static StringBuffer s1=new StringBuffer();
 public static boolean check(StringBuffer s2)
 {  StringBuffer s3=new StringBuffer(s2);
 String s5= s2.toString();
 s3.reverse();
 String s4= s3.toString();
 int a=s5.compareTo(s4); 
  if(a==0)
              return true;
        else 
            return false;            
    }
    
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter a string to check Palindrome ");
        s1.insert(0,sc.next());
       // System.out.println(s1);
        boolean a=check(s1);
        System.out.println("Palindrome"+" "+a);
    }    
}

Happy Coding!

Follow us on Instagram @programmersdoor

Join us on Telegram @programmersdoor


Please write comments if you find any bug in above code/algorithm, or find other ways to solve the same problem.

Follow Programmers Door for more.

#blog #interview #placement #learn #computer #science

        Contact Us

programmersdoor@gmail.com

  • LinkedIn
  • Facebook
  • Instagram

©2023 by Programmers Door