Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Anthony Pena

Greenhorn
+ Follow
since May 14, 2011
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
17
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Anthony Pena

Hunter McMillen wrote:I'm glad that it works like that, but there is still a better way of solving this that doesn't require those additional variables. Remove those variables and try moving around where you increment i_Fstlet and decrement i_Laslet.

Hunter


after i compare.. that way it compares the first two letters then returns a value before it even increments
10 years ago

Hunter McMillen wrote:Actually I was mistaken, the way you have your condition set up will work for both odd and even numbered palindromes. congrats.

Hunter




woo got it working thanks for all the help really appreciate it
10 years ago

Hunter McMillen wrote:Actually I was mistaken, the way you have your condition set up will work for both odd and even numbered palindromes. congrats.

Hunter


gah ok, well then how would i make it check against the first two letters and the middle two letters a case like bannah(just and example) my current code, would turn that out to be true
10 years ago

Hunter McMillen wrote:There is a different case you will have to handle in your loop depending on whether the word you are looking at has an odd or even number of letters.

Hunter


so for example, if the first and the last letters dont match, i want to stop it there and say its not a palindrome right away,
if they do match but the next to letters dont i want to stop it there, etc etc.. hm
10 years ago

Hunter McMillen wrote:

i need to increment both the end the first letter? but will this work for smaller words?


Try it out and let me know what you find.

Hunter






now, this works for the bigger words but any word with duplicate letters in the middle doesn't work (tried racecar and it returns true tried programming and it returned false but with the word cool it retured true..)
10 years ago

Hunter McMillen wrote:correct, so look at your loop and trace what you are comparing by hand. I'll use the example word "hannah" and do the first letter.



which letter positions do you need to increment/decrement to compare ( a and a)??
which letter positions are you incrementing?

Hunter


i need to increment both the end the first letter? but will this work for smaller words?
and what would happen in the middle if in a word like middle for instance? the rest of the word doesn't match but the two middle letters do.. hmm
10 years ago

Paul Clapham wrote:

Anthony Pena wrote:

Hunter McMillen wrote:hmm, well you aren't incrementing in the correct place. Try this, ignore the program for a bit and explain to me how you would determine whether a word was a palindrome on a piece of paper.


Hunter


you would compare the first and last, the second and second to last the third and third to last...
correct?



No, that isn't correct. You haven't said how or when you stop comparing. And your instructions don't make sense if there are only two letters, for example. You need to be clearer about such things.


well you stop comparing when you get to the middle of the word where both letters would be the same. if there are only to letters they would need to be the same?
10 years ago

Hunter McMillen wrote:hmm, well you aren't incrementing in the correct place. Try this, ignore the program for a bit and explain to me how you would determine whether a word was a palindrome on a piece of paper.


Hunter


you would compare the first and last, the second and second to last the third and third to last...
correct?
10 years ago

heres the new code, now its always set to true.. ill debug for a bit but any tips would be appreciated thanks in advance
10 years ago

Hunter McMillen wrote:you never increment the positions of the letters you are comparing, so the program compares the first and last letter forever.


Hunter


thanks!! makes sense !! awesome
10 years ago


if anyone could tell me whats going on here, i ran it through the a debugger but i am not yet experianced enough to identify the issue and fix it, any tips would be appreciated. thanks!
10 years ago

if anyone could tell me whats going on here, i ran it through the a debugger but i am not yet experianced enough to identify the issue and fix it, any tips would be appreciated. thanks!
10 years ago


so after alot of work thats what i got, it works, im happy lol
10 years ago

Campbell Ritchie wrote: . . . and have you done anything else with line 12?


im not sure what there is to do? i changed the name of the image to something more simple? should i try a different image?
10 years ago

Campbell Ritchie wrote:It looks as if the problem is on line 12.
You have made things difficult for yourself by trying to write the whole thing in one go. You ought to do it bit by bit.

Try printing the code base URL and the toString method of the Image to screen; then you can narrow down where the error occurs: is it code base or is it the image?

And the length of your actionPerformed method is a good example of why addActionListener(this) is poor, non-object-oriented programming. Even though there are lots of books which show such code.



java.lang.NullPointerException

at java.applet.Applet.getCodeBase(Applet.java:152)
at tictactoe.<init>(tictactoe.java:12)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:785)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:714)
at sun.applet.AppletPanel.run(AppletPanel.java:368)
at java.lang.Thread.run(Thread.java:662)
thats the one with the issue i think
10 years ago