As salamo alaikum wa rahmatullah
package examples;
import java.util.Scanner;
public class PalineDromeString {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
System.out.println("Enter String to check palindrome");
String str=sc.nextLine();
// Using the string buffer
StringBuilder sb=new StringBuilder();
sb.append(str);
StringBuilder sb1=sb.reverse();
System.out.println("Entered string is "+str);
System.out.println("Reverse string is "+sb1);
if(str.equals(sb1.toString()))
{
System.out.println("Entered string is palindrome");
}
else
{
System.out.println("Entered string is not palindrome");
}
}
}
Jazak Allah Khair
No comments:
Post a Comment