Home >>Java Programs >Java Program to determine whether a given string is palindrome
In this example, we will create a java program to check whether a given string is palindrome or not.
Any given string is said to be palindrome if it is same from both the ends.
public class Main
{
public static void main(String[] args)
{
String string = "adgfgda";
boolean flag = true;
string = string.toLowerCase();
for(int i = 0; i < string.length()/2; i++)
{
if(string.charAt(i) != string.charAt(string.length()-i-1))
{
flag = false;
break;
}
}
if(flag)
System.out.println("Given string is palindrome");
else
System.out.println("Given string is not a palindrome");
}
}