for (int i = len-2; index>= 0; index --)
+4
A:
You are using two variables: i
and index
, maybe this is causing trouble to you?
Konamiman
2009-10-25 21:04:55
+4
A:
Without any real context I would venture that int i
should be replaced with int index
.
Chris Bunch
2009-10-25 21:05:02
Also, unless you want to start at the *second to* last character, use (int index = len-1 ...
Chris Nava
2009-10-26 03:04:13
A:
You are looping through the string backwards? (I suppose that was your intention)
You are also not starting with the very last character in the string, you are starting with the second last (len-2).
theycallmemorty
2009-10-25 21:05:50
He might be leaving a newline character out of the loop. -1 for 0-based string length, -1 for the newline character (Cr, Lf).
Bobby
2009-10-25 21:34:46
@Bobby: We don't know that <code>len</code> is <code>str.length()</code>
Stefan Kendall
2009-10-25 22:55:08
+1
A:
Hard to tell from a single line of code, but why are you initializing i, and the checking and decrementing index? Try:
for (int index = len-2; index>= 0; index --)
zakk
2009-10-25 21:06:06