0% found this document useful (0 votes)
11 views

Program On String Buffer Class in Java

Write a program to check whether the given string is a palindrome or not using Stringbuffer class.

Uploaded by

Aman Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Program On String Buffer Class in Java

Write a program to check whether the given string is a palindrome or not using Stringbuffer class.

Uploaded by

Aman Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

b)Write a program to check whether the given string is a

palindrome or not using Stringbuffer class.


Source code:
import java.util.*;

// checking for pallindrome using StrignBuffer class

public class Test2 {

public static void main(String[] args){

Scanner sc = new Scanner(System.in);

System.out.println("Enter s String: ");

String s1 = sc.nextLine();

StringBuffer sb = new StringBuffer(s1);

sb.reverse();

String s2 = sb.toString(); // converting the StringBuffer to a String

System.out.println("Given String is: "+s1);

System.out.println("Reversed String is: "+s2);

// comparing s1 and s2

if(s1.equals(s2)){

System.out.println(s1+" is pallindrome.");

else{

System.out.println(s1+" is not pallindrome.");

}
OUTPUT:

You might also like