answersLogoWhite

0

import java.util.Scanner;

public class Palindrome{

public static void main(String[] args){

String front;

String back ="";

char[] failure;

String backwards;

Scanner input=new Scanner(System.in);

System.out.print("Enter a word: ");

front=input.next();

front=front.replaceAll(" ", "");

failure=front.toCharArray();

for (int i=0; i<failure.length; i++){

back=failure[i] + back;

}

if (front.equals(back)){

System.out.print("That word is a palindrome");

}else

System.out.print("That word is not a palindrome");

}}

User Avatar

Wiki User

14y ago

What else can I help you with?

Continue Learning about Engineering

Program to check that given string is palindrome or not in C?

/*To check whether a string is palindrome*/includeincludevoid main () { int i,j,f=0; char a[10]; clrscr (); gets(a); for (i=0;a[i]!='\0';i++) { } i--; for (j=0;a[j]!='\0';j++,i--) { if (a[i]!=a[j]) f=1; } if (f==0) printf("string is palindrome"); else printf("string is not palindrome"); getch (); }


How do you check given string is palindrome or not with out using string functions?

/*To check whether a string is palindrome*/includeincludevoid main () {int i,j,f=0;char a[10];clrscr ();gets(a);for (i=0;a[i]!='\0';i++){}i--;for (j=0;a[j]!='\0';j++,i--){if (a[i]!=a[j])f=1;}if (f==0)printf("string is palindrome");else printf("string is not palindrome");getch ();}


In a palindrome how to display the number of words or sentences entered?

To display the number of words or sentences in a palindrome, first, you need to check if the input string reads the same forwards and backwards. Then, you can split the string into words using a space or punctuation as a delimiter. Finally, count the number of words (or sentences, if counting full sentences) and present that count alongside the palindrome verification.


Write a pseudo logic to check whether a string is palindrome or not?

Prepare the string for processing: Remove all punctuation from the string (e.g., commas, hyphens, whitespace, etc). Convert to the same case (e.g., lower-case). Instantiate two pointers, one pointing at the first character, the other pointing at the last character. Process: If the two pointers are pointing at the same position or have crossed each other, the string is a palindrome. Otherwise, compare the characters being pointed at. If they are not equal, the string is not a palindrome. Otherwise, move both pointers one position towards the middle of the string and repeat the process.


Shell script to check if a string is a palindrome?

len=0i=1echo -n "Enter a String: "read strlen=`echo $str | wc -c`len=`expr $len - 1`halfLen=`expr $len / 2`while [ $i -le $halfLen ]doc1=`echo $str|cut -c$i`c2=`echo $str|cut -c$len`if [ $c1 != $c2 ] ; thenecho "string is not palindrome"exitfii=`expr $i + 1`len=`expr $len - 1`doneecho "String is Palindrome"

Related Questions

Program to check that given string is palindrome or not in C?

/*To check whether a string is palindrome*/includeincludevoid main () { int i,j,f=0; char a[10]; clrscr (); gets(a); for (i=0;a[i]!='\0';i++) { } i--; for (j=0;a[j]!='\0';j++,i--) { if (a[i]!=a[j]) f=1; } if (f==0) printf("string is palindrome"); else printf("string is not palindrome"); getch (); }


What are examples of a palindrome program forward and backwards?

To check if a string is a palindrome, point to each end of the string and work inwards towards the middle. If the characters pointed at differ, the string is not a palindrome. When the pointers meet or cross each other, the string is a palindrome. Note that the string cannot contain whitespace or punctuation and comparisons must not be case-sensitive.


Write a PHP program to check whether the string is palindrome or not?

You can do this: &lt;?php if ( $word === strrev( $word ) ) { echo "The word is a palindrome"; } else { echo "The word is not a palindrome"; }


Program for palindrome in php?

You could use a function like this:function isPalindrome($string) {$string = strtolower($string);return (strrev($string) == $string) ? true : false;}and then to check a palindrome call an if statement like so:if(isPalindrome($test)) {echo $test.' is a palindrome';}else {echo $test.' is not a palindrome';}


Prpogram in c to check the string is palindrom or not?

Here is a simple C program to check if a string is a palindrome: #include &lt;stdio.h&gt; #include &lt;string.h&gt; int main() { char str[100], rev[100]; printf(&quot;Enter a string: &quot;); fgets(str, sizeof(str), stdin); str[strcspn(str, &quot;\n&quot;)] = 0; // Remove newline character strcpy(rev, str); strrev(rev); // Reverse the string if (strcmp(str, rev) == 0) printf(&quot;The string is a palindrome.\n&quot;); else printf(&quot;The string is not a palindrome.\n&quot;); return 0; } This program takes a string input, reverses it, and then compares the original string with the reversed string to determine if it is a palindrome.


How do you write a program in C to check whether a word is a palindrome or not?

It is a simple program. i think u may understand it :#include#include#includevoid main(){char s[10]=answers.com;char x[10];int a;clrscr();strcpy(x,s);strrev(s);a=strcmp(s,x);if(a==0){printf("the entered string is palindrome");}else{printf("the entered string is not palindrome");}output:given string is not palindrome


How do you check given string is palindrome or not with out using string functions?

/*To check whether a string is palindrome*/includeincludevoid main () {int i,j,f=0;char a[10];clrscr ();gets(a);for (i=0;a[i]!='\0';i++){}i--;for (j=0;a[j]!='\0';j++,i--){if (a[i]!=a[j])f=1;}if (f==0)printf("string is palindrome");else printf("string is not palindrome");getch ();}


How do you write programs for String Reversal Palindrome check?

Copy and reverse the string. If the reversed string is equal to the original string, the string is a palindrome, otherwise it is not. When working with strings that hold natural language phrases (including punctuation, whitespace and so on) we must remove all the non-alphanumerics and convert the remainder to a common case, such as lower-case, prior to copying and reversing the string.


Write an algorithm to check whether a given string is palindrome or not?

#include &lt;stdio.h&gt; #include &lt;conio.h&gt; #include &lt;string.h&gt; void input(char a[ ]) { int i; printf("\n enter string\n"); scanf("%s",a); } void output(char a[ ]) { printf("\n string is %s",a); } int palindrome(char a[ ]) { int n,i; n=count(a); n=n-1; i=0; for(;a[n]==a[i] &amp;&amp; n&gt;=i;i++,n--); if(n&gt;=i) return 0; else return 1; } void main( ) { char a[80],b[80],s; int n; printf("\n check palindrome"); input(a); n=palindrome(a); output(a); if(n==1) printf("\n palindrome"); else printf("\n not palindrome"); getch(); }


Design a algorithm to check whether a given string is palindrome or not?

#include &lt;stdio.h&gt; #include &lt;conio.h&gt; #include &lt;string.h&gt; void input(char a[ ]) { int i; printf("\n enter string\n"); scanf("%s",a); } void output(char a[ ]) { printf("\n string is %s",a); } int palindrome(char a[ ]) { int n,i; n=count(a); n=n-1; i=0; for(;a[n]==a[i] &amp;&amp; n&gt;=i;i++,n--); if(n&gt;=i) return 0; else return 1; } void main( ) { char a[80],b[80],s; int n; printf("\n check palindrome"); input(a); n=palindrome(a); output(a); if(n==1) printf("\n palindrome"); else printf("\n not palindrome"); getch(); }


Design an algorithm to check whether a given string is a palindrome or not?

#include &lt;stdio.h&gt; #include &lt;conio.h&gt; #include &lt;string.h&gt; void input(char a[ ]) { int i; printf("\n enter string\n"); scanf("%s",a); } void output(char a[ ]) { printf("\n string is %s",a); } int palindrome(char a[ ]) { int n,i; n=count(a); n=n-1; i=0; for(;a[n]==a[i] &amp;&amp; n&gt;=i;i++,n--); if(n&gt;=i) return 0; else return 1; } void main( ) { char a[80],b[80],s; int n; printf("\n check palindrome"); input(a); n=palindrome(a); output(a); if(n==1) printf("\n palindrome"); else printf("\n not palindrome"); getch(); }


In a palindrome how to display the number of words or sentences entered?

To display the number of words or sentences in a palindrome, first, you need to check if the input string reads the same forwards and backwards. Then, you can split the string into words using a space or punctuation as a delimiter. Finally, count the number of words (or sentences, if counting full sentences) and present that count alongside the palindrome verification.