Jeremy Wages wrote:
is this checking if first letter == the last letter, 2nd letter == 2nd to last letter, etc?
Also, I interpreted "Note: Special characters, character case, and spaces should be ignored." As in I don't have to worry about account for/checking for (.equalsIgnoreCase() ) and he'll only use one word palindromes to check it?
Jeremy Wages wrote:
I had to do some googling to get an algorithm for the first part of the assignment (using either the character class or string class), but I also want to understand whats happening. Can you help me understand?
Henry Wong wrote:
Jeremy Wages wrote:
I had to do some googling to get an algorithm for the first part of the assignment (using either the character class or string class), but I also want to understand whats happening. Can you help me understand?
The way this question is worded, it seems to imply that you got a working example from the internet -- and is having trouble understanding it. Question. Does it actually work? ... meaning have you tested it with some example data?
Henry
Henry Wong wrote:
Question. Does it actually work? ... meaning have you tested it with some example data?
You mean making a list of the characters you do want? Since there are only 26 of them, that should be easy enough. That would match the customary conventions about palindromes whereMel Reams wrote:. . . The tricky part there is making a list of everything you don't want . . . It's a lot easier if you do the opposite.
...is usually considered a palindrome minus the space comma apostrophe and full stop, and case‑insensitive.Madam, I'm Adam.
Mel Reams wrote:No worries, I'm going to have to go to sleep before long too.
The thing with ignoring some characters is that there's a terrible way to do it and an easy way to do it. The terrible way is to look at each character and see if it's a special character or a space or punctuation or anything and ignore it and take the next character if it is. That will make a serious mess of your loop.
The easy way is to ignore all the stuff you don't want up front - that is, make a copy of your input string and strip out all the stuff you don't want. The tricky part there is making a list of everything you don't want - there are so many different special characters out there. It's a lot easier if you do the opposite.
Jeremy Wages wrote:Maybe the isLetter() method?
All things are lawful, but not all things are profitable.
Don't writeJeremy Wages wrote:. . .
Campbell Ritchie wrote:Have you explored the isLetter method?
I appear to have posted < 1″ before you.Jeremy Wages wrote:. . . I'm thinking what I posted wont work.
Campbell Ritchie wrote:
I appear to have posted < 1″ before you.Jeremy Wages wrote:. . . I'm thinking what I posted wont work.
No, it won't work.
Don't writeCampbell Ritchie wrote:
Henry Wong wrote:
Okay, I might be sounding like a broken record, but...
Admittedly, you will need to try a bit harder with your new code to break it though...![]()
Henry
Look where Mel Reams said there is a hard way and an easy way.Jeremy Wages wrote:. . . I can't find the advice mentioned earlier that I seemed to have missed.
Campbell Ritchie wrote:
Look where Mel Reams said there is a hard way and an easy way.Jeremy Wages wrote:. . . I can't find the advice mentioned earlier that I seemed to have missed.
Campbell Ritchie wrote:Doesn't his post give you any hints about which the easy way is?
Jeremy Wages wrote:I'll admit I had to google "how to extract only letters from a string" to come up with [^a-zA-z]+. How else would I have come up with it (not rhetorical)? Like if I didn't have access to google, would it just be familiarity with the syntax and general knowledge?
Mel Reams wrote:
That question is also why I was being a bit vague and mysterious when I was hinting about how you should solve the problem - if I just tell you the answer then you don't learn nearly as much and I want to actually help, not leave you in a position where you can't do it without us.
No, that won't work. You can write something like Madam and have it show correctly as a palindrome, but that will also show Saddam as a palindrome. [Actually it won't, because of the capital letters, but there is an easy way to correct that.] That is because it is only testing one pair of letters and not taking any action when you get false. I think I shall have to let you out of your misery. Instead of lines 13‑20, write this:You need to start with true otherwise the loop will never start. I like to use characteristics of objects in loops rather than separate variables. If your predicate is false, you terminate the loop at that point. I challenge you to reduce lines 21‑25 to one line with the ?: operator. It is probably easier with printf than println.Jeremy Wages wrote:. . .
Crusading Chameleon likes the size of this ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
|