Tuesday, 21 July 2015

Java program to check whether a string is palindrome or not ....

Here is the code....


       

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class test2 {

 static boolean isPalindrome(String s) {

  int y = 0;
  for (int u = s.length() - 1; u >= 0; u--) {
   if (s.charAt(y) != s.charAt(u))
    return false;
   y++;
  }

  return true;
 }

 public static void main(String args[]) throws Exception {

  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  String str = br.readLine();
  System.out.println(isPalindrome(str));
 }

}
       
 

No comments:

Post a Comment