posted 24 years ago
If you want to loop through a String you might want to try a StringReader (though this might be overkill for 5 character palindromes). Here's and example:
Or if you want to read the whole string try this
Of course, you can also use the String.getChars() method to return the same array of chars as example2 above. Look at the java docs for more info on this.
Also, as a point of interest, notice that if you checking a string for a palindrome,
1) if the string is an even # of chars, then split the string down the middle, reverse one of them and then they should be identical.
2) if the string is an odd # of chars, then take (n-1)/2 from the beginning and end, flip one and compare as above.
Soooo....you might notice that if you create two char[] arrays and use the StringBuffer to populate them accordingly...
Fun stuff!
Sean
[This message has been edited by Sean MacLean (edited November 09, 2000).]