How to check given String is Palindrome or Not using Java?
import java.util.*;
class WordPalindorome
{
public static void main(String[] args)
{
int div=0 ,n;
Scanner sc = new Scanner(System.in);
System.out.println(" enter the word");
String s = sc.nextLine();
char str[]=s.toCharArray();
n= str.length;
for(int i =0;i<n;i++)
{
if(str[i]!=str[n-i-1])
{
div++;
break;
}
}
if(div == 0)
{
System.out.println("hai");
}
else
{
System.out.println(" nhi hai");
}
}
}
Comments
Post a Comment