Advertisement
haikelfazzani

Java : Check If A Word Is Palindrome Or Not

Aug 29th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.38 KB | None | 0 0
  1. public static boolean PalindromeWord(String word) {
  2.        
  3.         char[] ch=word.toCharArray();
  4.         int i=0,j=word.length()-1;
  5.         boolean check=false;
  6.        
  7.         while(i<j) {
  8.             if(ch[i] == ch[j]) check=true;
  9.             else check=false;
  10.            
  11.             i++;
  12.             j--;
  13.         }
  14.         return check;
  15.     }
  16.    
  17.     public static void main(String[] args) {
  18.        
  19.         String word="haah";
  20.         System.out.println(PalindromeWord(word));
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement