Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class PalindromeCheck{
  4.  
  5. public static void main(String[] args){
  6.  
  7. BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
  8. try{
  9.  
  10. System.out.print("Enter a sentence: ");
  11. String sentence = dataIn.readLine();
  12. PalCheck(sentence);
  13.  
  14. }catch(IOException e){
  15.  
  16. e.printStackTrace();
  17. System.err.println(e);
  18.  
  19. }
  20. }
  21.  
  22. public static void PalCheck(String s){
  23.  
  24. String end = "";
  25. String result = s.replaceAll(" ", "");
  26. for ( int i = result.length() - 1; i >= 0; i-- )
  27. end = end + result.charAt(i);
  28.  
  29. if (result.equalsIgnoreCase(end))
  30. System.out.println( result + " is a palindrome.");
  31. else
  32. System.out.println(result + " is not a palindrome.");
  33.  
  34.  
  35. }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement