Computer Science, asked by thanujvenugopal, 1 year ago

write a program to accept a word and check and print weather the word is palindrome or special word using scanner (in java)

Answers

Answered by Mathfear
28
I am only writing the logic of that program.Pls ignore the Syntax error.

Scanner obj=new Scanner(System.in));
S.o.p(" Enter a String");
String S =obj.nextLine();

String S1=S,S2="";
for(int i=S.length()-1;i>=0;i--)
{
S2=S2+S.charAt(i);
} if(S1.equals(S2))
{
S.o.p("palindrome String="+S1);
}
else
{
S.o.p("not palindrome String="+S1);
}
.

Mathfear: no
thanujvenugopal: i will met you there
thanujvenugopal: oh ok
thanujvenugopal: which country are you from??
Mathfear: hhahah India
thanujvenugopal: which state??
Mathfear: UP ,Raebareli
thanujvenugopal: oh
thanujvenugopal: bye then its late
Mathfear: yeah! bye
Answered by QGP
37
import java.util.Scanner;
public class Palindrome_Word
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
       
        int i,l;
        String s,p="";
       
        System.out.print("Enter the word: ");
        s = sc.next();
       
        String s1 = s.toLowerCase();
       
        l = s1.length();
       
        for(i=0;i<l;i++)
        {
            p=p+s1.charAt(l-i-1);
        }
       
       
        if(s1.equals(p))
        {
            System.out.println(s+" is a palindrome.");
        }
        else
        {
            System.out.println(s+" is not a palindrome.");
        }
    }
}

       


QGP: This program also takes care of the case, when all letters are not of the same case. For example,if you input "Madam", it will show that It IS a palindrome
QGP: Please mark as brainliest if you like it
thanujvenugopal: hey what is special number can you tell how to check it also
QGP: A Special Number is a number whose sum of factorial of digits is equal to the number itself. For example: 145
QGP: 1! + 4! + 5! = 145
QGP: So 145 is a Special Number
thanujvenugopal: then what is special word
QGP: Well Honestly I have never heard of "Special Word"
thanujvenugopal: oh
thanujvenugopal: i also dont know it that's why i posted it here
Similar questions