SHARE
TWEET

Untitled

a guest Apr 20th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top