help needed urgently project work
nayomi21 (1)

an interactive java code asking a client to input a string and to test if the string is a palindrone

You are viewing a single comment. View All
ArchieMaclean (590)

You would want to loop through the string and check that the first character is the same as the last, the second the same as the second last, and so on. I won't give you the whole solution but this should help you work it out:

You want to have a variable storing the length of the string (e.g. string_length). Then you want to loop string_length times, with a counter (say i). Then you can check if the first/last e.t.c. characters are equal using (assuming the string is called myString):
if (myString.charAt(i) == myString.charAt(string_length-i-1) // if it is equal
That -1 at the end is needed because of zero-indexing; without it, there would be an out of bounds exception.
If this is false, then you know that the string is not a palindrome.

I hope this helped, and please mark it as the answer if it solved your problem :) If you need more elaboration on any points, just reply to this comment and I will get back to you.