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..
palindrome, if the user inputs "what" the output is "thaw"
Collapse
X
-
There are many ways of doing this.Originally posted by Dullmei 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..
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? -
Are you trying to write a code to reverse a string or to check if a given word is a palindrome?Originally posted by Dullmei 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..
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" etcComment
-
well I am not sure if this can be called a plaindrome
I am putting some more examples..."fall leaves after leaves fall"
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 sinnedOriginally posted by abctechAre 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" etcComment
-
Word palindromes are sentences that are read in either direction word by word.Originally posted by hirak1984"fall leaves after leaves fall"
well I am not sure if this can be called a plaindrome
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/PalindromeComment
-
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.Code:import java.io.*; public class Pal { public static void main (String args[])throws Exception { String character; //char word; char[] temp; temp = new char[15]; char i; System.out.println("Input word:"); for (i=0;i<14;i--) { InputStreamReader word= new InputStreamReader(System.in); BufferedReader word2=new BufferedReader(word); character=word2.readLine(); //character=String.parseInt(character); //temp[i]=character; } //System.out.println ("Palindrome: "); for (i=0;i<14;--i) { System.out.print ("Palindrome: "+temp[i]); } } }
Please help!Comment
-
Get the word as a string with the readline method. No need for a for loop for that.Originally posted by DullmeThat 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.Code:import java.io.*; public class Pal { public static void main (String args[])throws Exception { String character; //char word; char[] temp; temp = new char[15]; char i; System.out.println("Input word:"); for (i=0;i<14;i--) { InputStreamReader word= new InputStreamReader(System.in); BufferedReader word2=new BufferedReader(word); character=word2.readLine(); //character=String.parseInt(character); //temp[i]=character; } //System.out.println ("Palindrome: "); for (i=0;i<14;--i) { System.out.print ("Palindrome: "+temp[i]); } } }
Please help!
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.Comment
Comment