Wednesday 22 February 2017

JAVA Program to check whether a given string is palindrome or not without taking the concept of reverse

.import java.util.*;
class StringPalindrome {

public static void main(String[] args)
{
String str;
int l,c=0;
Scanner s= new Scanner(System.in);
System.out.println("enter a string");
str= s.nextLine();
l=str.length();
for(int i=0;i<(l-1)/2; i++)
{
if(str.charAt(i)==str.charAt(l-1-i))
{
continue;
}
else
{
c++;
}
}
if(c==0)
System.out.println("the given string is a pallindrome");
else
System.out.println("the given string is a not pallindrome");

}

}

Output
enter a string
katak
the given string is pallindrome

No comments:

Post a Comment