Social Icons

Wednesday, 25 September 2013

check palindrome in java

import java.util.Scanner;
class pldm
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println("Enter a String which is palindrome ");
String s=in.nextLine();

if(ispalindrome(s))
{
System.out.println("word is palindrome");
}
else
System.out.println("word is not palindrome");
}

public static boolean ispalindrome(String s1)
{
int low=0;
int high=s1.length()-1;

  while(low<high)
{
if(s1.charAt(low)!=s1.charAt(high))
 {
return false;
 }
low++;
high--;
 }
 return true;

}
}







No comments:

Post a Comment

 

Sample Text

Sample text

 
Just Programming Cse DriveReputation Management