Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class stringPalindrome {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Scanner input = new Scanner(System.in);
  8. //Prompt
  9. System.out.println("Enter the word to check if it's a palindrome: ");
  10. String word = input.nextLine();
  11.  
  12. palindrome(word);
  13. }
  14.  
  15. public static void palindrome(String w) {
  16.  
  17. String b = "";
  18. int i = w.length();
  19. for (int k = i - 1; k >= 0; k--) {
  20. b = b+w.charAt(k);
  21. }
  22.  
  23. if (w.equalsIgnoreCase(b))
  24. System.out.println("The word is a palindrome!");
  25.  
  26. else
  27. System.out.println("Not a palindrome!");
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement