Q.11 Find whether entered String is Palindrome or not.
import java.util.Scanner;
public class StringPal{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter String");
String s=sc.next();String s1="";
for(int i=s.length()-1;i>=0;i--){
s1=s1+s.charAt(i);
}
System.out.println(s1);
if(s1.equals(s)){
System.out.println("palindrome");
}
else{
System.out.println("not palindrome");
}
}
}
No comments:
Post a Comment