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");
}
}
}
//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;
}
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
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
}
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!");
}
}
}
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]", ""); }
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.
sdfdg
You don't have to write palindrome programs in wikipedia.
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>0) { r=n % 10; sum=concat(r); n=n / 10; } print r;
This program only suits PHP. If you want a proper one try C program for it available on web <body> <?php if(isset($_POST['submit'])) { $text = $_POST['text']; $string = mysql_real_escape_string($text); $invert = strrev($string); if($string == $invert) { echo "<br>Given number is a palindrome!!"; } else { echo "<br>Given number is not a palindrome!!"; } } ?> <form method="post"> <input type="text" name="text" id="text" /> <input type="submit" name="submit" value="Submit" id="submit" onclick="<?php $_SERVER['PHP_SELF']; ?>" /> </form> </body>
what is string
You can do this: <?php if ( $word === strrev( $word ) ) { echo "The word is a palindrome"; } else { echo "The word is not a palindrome"; }
sdfdg
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 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.
You don't have to write palindrome programs in wikipedia.
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>0) { r=n % 10; sum=concat(r); n=n / 10; } print r;
This program only suits PHP. If you want a proper one try C program for it available on web <body> <?php if(isset($_POST['submit'])) { $text = $_POST['text']; $string = mysql_real_escape_string($text); $invert = strrev($string); if($string == $invert) { echo "<br>Given number is a palindrome!!"; } else { echo "<br>Given number is not a palindrome!!"; } } ?> <form method="post"> <input type="text" name="text" id="text" /> <input type="submit" name="submit" value="Submit" id="submit" onclick="<?php $_SERVER['PHP_SELF']; ?>" /> </form> </body>
int pallindrom(int p){ /*write all logic*/ }
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.
what is string
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.
i dont no string for servlate