answersLogoWhite

0


Best Answer

import java.io.*;

class StringPalindrome

{

static void main()throws IOException

{

InputStreamReader isr=new InputStreamReader(System.in);

BufferedReader br= new BufferedReader(isr);

System.out.println("Enter a word");

String input=br.readLine();

int x= input.length();

char ans;

String fin="";

for(int y=x-1; y>=0; y--)

{

ans=input.charAt(y);

fin=fin+ans;

}

System.out.println("The reverse is " + fin);

if(fin.equalsIgnoreCase(input))

{

System.out.println("Palindrome");

}

else

{

System.out.println("Not a palindrome");

}

}

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

//call this method inputing the string you want to test

private void palindromeTest(String input){

String output = """+input+"" "; output = output +

((getReverseString(input).equals(input)) ?

"is a palindrome" : "is not a palindrome");

System.out.println(output);

}

private String getReverseString(String input){

String revInput = "";

for(int i=input.length(); i>0; i--)

{

revInput= revInput + input.charAt(i-1);

System.out.println(revInput);

}//end i

return revInput;

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

StringBuilder sb = new StringBuilder("Palindrome goes here");

String bs = new String(sb.reverse().toString());

System.out.println(bs.equals(sb.toString()));

//I'm not writing the whole program, this should get you started. if output = true, then the string was a Palindrome, else it wasn't

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Use a loop to check if the first and last characters in the string are the same, then check the second and second to last.

put this in any chass and it will return true or fasle for if the string passed is a palindrome.

public static boolean palindrome(String text){

for(int i = 0; i < text.length()-1; i++){

int lastChar = text.length()-1;

if(text.charAt(i)!=text.charAt(lastChar-i)){//if the characters are not the same, then it is not a palindrome.

return false;

}

}

return true;//if all the characters fit then it must be a palindrome

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

import java.io.*;

public class Palindrome {

public static void main(String [] args){

try{

BufferedReader object = new BufferedReader(

new InputStreamReader(System.in));

System.out.println("Enter number");

int num= Integer.parseInt(object.readLine());

int n = num;

int rev=0;

System.out.println("Number: ");

System.out.println(" "+ num);

for (int i=0; i<=num; i++){

int r=num%10;

num=num/10;

rev=rev*10+r;

i=0;

}

System.out.println("After reversing the number: "+ " ");

System.out.println(" "+ rev);

if(n == rev){

System.out.print("Number is palindrome!");

}

else{

System.out.println("Number is not palindrome!");

}

}

catch(Exception e){

System.out.println("Out of range!");

}

}

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

public static void main(String[] args) { UserInterface ui = new UserInterface(); Stack stack = new Stack(); Queue queue = new Queue(); String cleaned = new String(); boolean palindrome = true; ui.setString("Please give me a palindrome."); cleaned = ui.cleanString(ui.getString()); for (int i = 0; i < cleaned.length(); ++i) { stack.push(cleaned.charAt(i)); queue.enqueue(cleaned.charAt(i)); } while (!stack.isEmpty() && !queue.isEmpty()) { if (stack.pop() != queue.dequeue()) { palindrome = false; } } if (palindrome) { System.out.printf("%s is a palindrome!", ui.getString()); } else System.out.printf("%s is not a palindrome :(", ui.getString()); stack.dump(); queue.clear(); } public class Stack { public void push(char c) { c = Character.toUpperCase(c); Node oldNode = header; header = new Node(); header.setData(c); header.setNext(oldNode); } public char pop() { Node temp = new Node(); char data; if (isEmpty()) { System.out.printf("Stack Underflow (pop)\n"); System.exit(0); } temp = header; data = temp.getData(); header = header.getNext(); return data; } } public class Queue { public void enqueue(char c) { c = Character.toUpperCase(c); Node n = last; last = new Node(); last.setData(c); last.setNext(null); if (isEmpty()) { first = last; } else n.setNext(last); } public char dequeue() { char data; data = first.getData(); first = first.getNext(); return data; } } public String cleanString(String s) { return s.replaceAll("[^A-Za-z0-9]", ""); }

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

If you do not know how to program/code or how to program/code using the Java language, then you need to go on a course to learn these skills.

Once you have these skills you need to write some code that reverses the characters making up the number (or word) then compares each character in turn with the original. If all the character match, you have a palindrome.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a java program to find weather a given string is a palindrome or not?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

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"; }


Write c program to print palindrome using string without using strrev strlen strcam?

sdfdg


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


Write programs for String Reversal and Palindrome check?

Write your program and if you are having a problem post it here with a description of the problem you are having. What you are asking is for someone to do your homework for you.


How do you write a palindrome program in c in Wikipedia?

You don't have to write palindrome programs in wikipedia.


Write a program using method plainto check whether a string is a palindrome or not A palindrome is a string that reads the same from left to right and vice-versa?

Palindrome number is a number like 121 which remains the same when its digits are reversed. To find this number in a simple java program, just follow the below way. sum = 0; while(n&gt;0) { r=n % 10; sum=concat(r); n=n / 10; } print r;


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

This program only suits PHP. If you want a proper one try C program for it available on web &lt;body&gt; &lt;?php if(isset($_POST['submit'])) { $text = $_POST['text']; $string = mysql_real_escape_string($text); $invert = strrev($string); if($string == $invert) { echo "&lt;br&gt;Given number is a palindrome!!"; } else { echo "&lt;br&gt;Given number is not a palindrome!!"; } } ?&gt; &lt;form method="post"&gt; &lt;input type="text" name="text" id="text" /&gt; &lt;input type="submit" name="submit" value="Submit" id="submit" onclick="&lt;?php $_SERVER['PHP_SELF']; ?&gt;" /&gt; &lt;/form&gt; &lt;/body&gt;


How do you write palindrome program in c language?

int pallindrom(int p){ /*write all logic*/ }


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 a program to implement the various operations on string such as length of string concatenation reverse of a string copy of a string to another in VB?

what is string


What are the explanation steps for palindrome program?

If you want to check whether a string is a palindrome, you can reverse the string (for example, the Java class StringBuffer has a reverse() method), and then compare whether the two strings - the original string and the reverted string - are equal. Alternately, you could write a loop that checks whether the first character of the string is equal to the last one, the second is equal to the second-last one, etc.; that is, you have a counter variable (in a "for" loop) that goes from zero to length - 1 (call it "i"), and compare character #i with character #(length-i-1) inside the loop.


Write a program in java to display a string message using Servlets?

i dont no string for servlate