Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Palindrome
  4. {
  5. public static void main(String[] args)
  6. {
  7. String word,reverse, same;
  8. word = phrase();
  9. reverse = flip(word);
  10. match(word, reverse);
  11.  
  12. }
  13. public static String phrase()
  14. {
  15. String word;
  16. Scanner keyboard = new Scanner(System.in);
  17. System.out.println("Please enter a word: ");
  18. word = keyboard.nextLine();
  19.  
  20. return word;
  21. }
  22. public static String flip(String sentence)
  23. {
  24. String reverse;
  25. reverse = "";
  26. int length = sentence.length();
  27.  
  28. for(int i = length - 1; i >= 0; i--)
  29. {
  30. reverse = reverse + sentence.charAt(i);
  31. }
  32.  
  33. return reverse;
  34. }
  35. public static void match(String original, String backward)
  36. {
  37. if(original.equalsIgnoreCase(backward))
  38. {
  39. System.out.println("\" " + original + " \" is a palindrome");
  40. }
  41. else
  42. {
  43. System.out.println("\" " + original + " \" is not a palindrome");
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement