Reply
Wed 17 Sep, 2003 04:11 pm
can you teach me how to write a java program a very simple one to produce a palindrome from a given input string using cocatenations with one or more methods of a word class? how would you write a word class and and test class to instantiate word object from the input string? can you show me how to output it to an output stream using the system.out.println? is this the method of printing it out? are there any online tutorials about this? would you mind teaching me??
"palindrome from a given input string using cocatenations with one or more methods of a word class"
what do you mean by that?
what does this "test class" do?
and where is the input coming from?
output is System.out.println(). the S is capitalized. i've spent many nights trying to figure out why programs didn't work only to find that the S wasn't capitalized.
i'm sure there are plenty of tutorials out there. search google. for usage of specific methods consult the sun java api.
gee, this sounds a LOT like a freshman computer science major... you can look up the "word class" on your own... but this is how you're gonna do it: create two instances of a word class, inputWord and PalWord. but will start out as empty strings. read your input string into the inputWord variable. you should be able to access each element of the variable (each character of the string) using an access operator with a numerical index. ex: if the input word is "computer", then the value returned by inputWord[2] would be the character 'm'. however the access method may look like inputWord.get(2) or inputWord.at(2). so you'll have to read the document files on the word class. so anyway, make a loop that starts with the last element in the input string and appends it to the palidrome string. something like :
for(int counter = length of inputWord; while counter is greater than 0; subtract 1 from counter){
palWord = palWord + inputWord.get(counter);
}//end for loop
that was written in C++ syntax... but it should be nearly identical to what you need.... that's the basics, hope it helps.
Here is a link to a program that (believe it or not) does exactly this. It is written in C and is quite possible the most beautiful piece of code ever written -- so good, in fact, it won a contest.
Go ahead, check it out, you won't be disappointed.
http://www.acme.com/software/c.otto.c/
(No really, all of you should look at this!)
ebrown, I'm not a C programmer so no doubt I'm not fully appreciating the genious of that code, but still...damn that's cool.
No no no, the most beautiful piece of code ever written was in 6502 binary machine code that took advantage of a regular glitch in the clock signal to squeeze one more instruction out of the processor every 20 cycles.
*breathes on fingernals and buffs them on my Tool t-shirt.*
Heliotrope wrote:No no no, the most beautiful piece of code ever written was
...BitTorrent. Written in Python. Go Python.
I just dig Python becuase I use it to write mathmatical tutoring program for my 8 your old neph. Python is simple and powerful. And BitTorrent kicks ass.
This might be appropriate here, at least it is a good read. Every programmer should certainly know this story -- The Legend of Mel
http://www.farid-hajji.net/fun/cj-progmachine.html
jpowell wrote:Written in Python.
I've not heard of this one. Mind you though I'm 20 years out of date when it comes to programming.
I did all my stuff on BBC Micros, Commodore 64s and ZX Spectrums with 6502A and Z80A 8 bit processors.