Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class specialpalin
- {
- static Scanner key = new Scanner(System.in);
- public static void main(String ar[])
- {
- System.out.print("Enter a word: ");
- String test = key.next();
- if(palindromeCheck(test)) System.out.println("Is a palindrome!");
- else System.out.println("Not a palindrome!");
- if(specialCheck(test)) System.out.println("Is a special word!");
- else System.out.println("Not a special word!");
- }
- public static boolean palindromeCheck(String s)
- {
- StringBuffer obj = new StringBuffer(s);
- if(s.equals(obj.reverse().toString())) return true;
- else return false;
- }
- public static boolean specialCheck(String s)
- {
- String a = String.valueOf(s.charAt(0));
- String b = String.valueOf(s.charAt((s.length()-1)));
- if(a.equalsIgnoreCase(b)) return true;
- else return false;
- }
- }
Add Comment
Please, Sign In to add comment