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
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);
}
.
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
Answered by
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.");
}
}
}
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.");
}
}
}
Similar questions
Social Sciences,
8 months ago
Math,
8 months ago
Geography,
8 months ago
Chemistry,
1 year ago
Hindi,
1 year ago
Social Sciences,
1 year ago
Math,
1 year ago
Biology,
1 year ago