The above program trying to show wheather any character is palindrome or not by having an input at command prompt. But when I entered an input radar, it is showing me an outofbound Exception.
The stackstace for the out of bounds exception, not only tells you the exact method and line number where it is happening -- it also tells you the index as well. This way, you can tell if you overflowed or underflow.
But in your case, are you sure you actually want to deference the array? Shouldn't you be checking start? not e[start]?
Henry [ December 16, 2008: Message edited by: Henry Wong ]
One remark on how to slightly improve your algorithm:
you only need to go half-way. After you have hit the half-way point you will compare the same elements again. For instance, the last comparison is that of e[e.length - 1] and e - but you've already compared e with e[e.length - 1].
So the check can become Should e.length be odd, this will miss one element but that is one element that you would compare with itself.
Just a piece of advice, you don't need to traverse the whole array. As you are moving from both sides each traversing the halves from both end. Your loop should run half way only i.e round(e.length/2)+1, because anyways after length/2 it is going to compare the same elements For example RADAR it checks R=R --> f=0,l=4 A=A --> f=1,l=3 D=D --> f=2,l=2 A=A --> f=3,l=1 ---> useless R=R --> f=4,l=0 ---> useless