OK I am not sure if any of you here are also coming from the C++ forum, but I finished my C++ class, got an A, thanks to all your help, and now I am onto Java.
I am still a beginner in both Java and C++ and there is more work ahead of me to finally know enough to be able to effectively participate in these fora.
For now, the Java class requires us to write a program that will determine if a string is a palindrome or not.
My theory/approach is:
Get the string from the user.
Check if it has an even number of characters or an odd number of characters using the Mod % operand. If it has an odd number of characters then I will have what I call a pivot character where by what is on the left of this character is equal to what is on the right, and I can discard the pivot character.
Split the string into the two parts on either side of the pivot. If even, then I will have equal sides, so the division will happen without discarding any characters.
Now here comes the question(s):
Should I reverse one part and check if it is equal to the other part, this will require a For loop which might take time, and then simply say if FirstPartString Isequal(LastPartString) = TRUE then we have a palindrome.
Simply compare the two parts of the string going backwards, so character at index 0 will be compared to character at index String.Lenghth(); which will also require a For loop, but will eliminate the equality check step. Once I find a character that is not the same, boom, exit loop and announce that it is not a palindrome.
What is the most efficient way to do this kind of an assignment? No arrays can be used since we did not cover arrays so far.
Also, should I eliminate the spaces between the words, and match up the characters, because some times the spaces do come in the way. If so, what is the best way to remove the white space from a sting? ReplaceAll will have to go character by character, and that is IMHO slow. Any suggestions?