JavaNo Comments

default thumbnail

Palindrome is nothing it is just same reverse of string like example : MADAM it is a palindrome using Array. Below example will show you how to find Palindrome words in string.

Find Palindrome Words in String

import java.util.Scanner;
class palidrom
{
public static void main(String arg[])
{
String rev=””;
System.out.println(“Enter any String and check its palindrome or Not”);
Scanner sc=new Scanner(System.in);
String str=sc.nextLine(); // String store
int s=str.length(); // String length store in integer
for(int i=s-1;i>=0;i–){ //example string madam int length =5
rev=rev+str.charAt(i);
}
if(str.equals(rev))
{
System.out.println(str + ” is a palindrome”);
}
else
{
System.out.println(str + ” is not palindrome”);
}}}

If you have any issue comment us in the comment box. Our experts will reply you as soon as possible.

Be the first to post a comment.

Add a comment