Computer Science, asked by Ashvi16, 1 year ago

WAP to accept a word and check whether the word is palindrome or not.
for example- madam,dad, arora
(in java)

Answers

Answered by DamEleStef
4
import java.io.*;
class pal
 {
   public static void main()throws IOException
    {
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a word");
String w,w1="",w2="";
w=in.readLine();
char ch;
int l,i;
l=w.length();
w1=w;
for(i=0;i<l;i++)
{
ch=w1.charAt(i);
w2=ch+w2;
}
if(w.equals(w2)==true)
S.o.pln("PALINDROME WORD="+w)
}
}
I hope it's correct....

Ashvi16: can u do in any other method
Answered by QGP
5
import java.io.*;
public class Palindrome
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                int i,l;
                String s,p="";
                System.out.print("Enter the word: ");
                s = in.readLine();
                l = s.length();
                for(i=0;i<l;i++)
                {
                     p=p+s.charAt(l-i-1);
                }
                if(s.equals(p))
               {
                     System.out.println(s+" is a palindrome.");
                } 
                 else 
                {
                     System.out.println(s+" is not a palindrome.");
                }
    }
}
        
Similar questions