By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,341 Members | 1,364 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,341 IT Pros & Developers. It's quick & easy.

palindrome, if the user inputs "what" the output is "thaw"

P: 3
i can hardly know what is the code for this. I have researched palindromes, but unfortunately, I only have read about integers not for characters..I need some help..
Feb 23 '07 #1
Share this Question
Share on Google+
9 Replies


10K+
P: 13,264
i can hardly know what is the code for this. I have researched palindromes, but unfortunately, I only have read about integers not for characters..I need some help..
There are many ways of doing this.
Surely you must have an idea of your own on how to do it? Let's start with the more difficult one. If you were told to this this by making use of a char array, how would you do it?
Feb 23 '07 #2

100+
P: 157
i can hardly know what is the code for this. I have researched palindromes, but unfortunately, I only have read about integers not for characters..I need some help..
Are you trying to write a code to reverse a string or to check if a given word is a palindrome?

As far as I know a palindrome is a word, phrase, verse, or sentence that reads the same backward or forward.
Eg: Dad, Madam, "fall leaves after leaves fall" etc
Feb 23 '07 #3

hirak1984
100+
P: 316
well I am not sure if this can be called a plaindrome
"fall leaves after leaves fall"
I am putting some more examples...
Don't nod
Dogma: I am God
Never odd or even
Too bad I hid a boot
Rats live on no evil star
No trace; not one carton
Was it Eliot's toilet I saw?
Murder for a jar of red rum
May a moody baby doom a yam?
Go hang a salami; I'm a lasagna hog!
Satan, oscillate my metallic sonatas!
A Toyota! Race fast... safe car: a Toyota
Straw? No, too stupid a fad; I put soot on warts
Are we not drawn onward, we few, drawn onward to new era?
Doc Note: I dissent. A fast never prevents a fatness. I diet on cod
No, it never propagates if I set a gap or prevention
Anne, I vote more cars race Rome to Vienna
Sums are not set as a test on Erasmus
Kay, a red nude, peeped under a yak
Some men interpret nine memos
Campus Motto: Bottoms up, Mac
Go deliver a dare, vile dog!
Madam, in Eden I'm Adam
Oozy rat in a sanitary zoo
Ah, Satan sees Natasha
Lisa Bonet ate no basil
Do geese see God?
God saw I was dog
Dennis sinned
Are you trying to write a code to reverse a string or to check if a given word is a palindrome?

As far as I know a palindrome is a word, phrase, verse, or sentence that reads the same backward or forward.
Eg: Dad, Madam, "fall leaves after leaves fall" etc
Feb 23 '07 #4

100+
P: 157
"fall leaves after leaves fall"
well I am not sure if this can be called a plaindrome
Word palindromes are sentences that are read in either direction word by word.
Eg:
First ladies rule the state, and state the rule,"Ladies First."
Fall leaves after leaves fall.

Ref:-
You can find the above examples under 'Symmetry by words' in http://en.wikipedia.org/wiki/Palindrome
Feb 23 '07 #5

10K+
P: 13,264
Alright then. I'll copy this to the cafe forum.
Feb 23 '07 #6

P: 3
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2.   public class Pal
  3.  {
  4.     public static void main (String args[])throws Exception
  5.   {
  6.     String character;
  7.     //char word;
  8.      char[] temp; 
  9.      temp = new char[15];
  10.      char i;
  11.  
  12.         System.out.println("Input word:");
  13.         for (i=0;i<14;i--) 
  14.          {
  15.               InputStreamReader word= new InputStreamReader(System.in);
  16.               BufferedReader word2=new BufferedReader(word);
  17.               character=word2.readLine();
  18.               //character=String.parseInt(character);
  19.               //temp[i]=character;
  20.          }
  21.               //System.out.println ("Palindrome: ");
  22.                 for (i=0;i<14;--i)
  23.              {
  24.                System.out.print ("Palindrome: "+temp[i]);    
  25.               }              
  26.   }
  27.  }
That is my code.My problem is that, how can I make the user's word input to its opposite word? Example: He inputs MILK.. The output shoud be KLIM.
Please help!
Mar 6 '07 #7

10K+
P: 13,264
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. public class Pal
  3. {
  4. public static void main (String args[])throws Exception
  5. {
  6. String character;
  7. //char word;
  8.     char[] temp; 
  9.     temp = new char[15];
  10.     char i;
  11.  
  12. System.out.println("Input word:");
  13.         for (i=0;i<14;i--) 
  14.     {
  15.           InputStreamReader word= new InputStreamReader(System.in);
  16.         BufferedReader word2=new BufferedReader(word);
  17.         character=word2.readLine();
  18.         //character=String.parseInt(character);
  19.         //temp[i]=character;
  20.     }
  21.      //System.out.println ("Palindrome: ");
  22.      for (i=0;i<14;--i)
  23.     {
  24.           System.out.print ("Palindrome: "+temp[i]);    
  25.          } 
  26. }
  27. }
That is my code.My problem is that, how can I make the user's word input to its opposite word? Example: He inputs MILK.. The output shoud be KLIM.
Please help!
Get the word as a string with the readline method. No need for a for loop for that.
Then get its length using the string.length() method. After that you can now form a string by adding characters from the last to the first using a for loop.
Mar 6 '07 #8

P: 1
example codes of palindrome in NetBeans with interface
Mar 8 '07 #9

10K+
P: 13,264
example codes of palindrome in NetBeans with interface
Write them yourself like the OP is trying to do here. You will learn better that way.
Mar 8 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.