![]() |
Need help with ArrayIndexOutOfBoundsException
I'm just learning java and I thought I would try my hand at making a program that would print a string backwards. So what I tried to do was write out the text from the string in a character array and then fill another character array from end to beginning. Problem is I keep getting an ArrayIndexOutOfBoundsException error every time. I'm not sure what's wrong considering I tested the length of stringholder1 and it was 22, so I don't see why I'm getting the error.
Here's the code: Code:
package classtest; |
Code:
for(int i=1;i<23;i++) {Avoid the magic numbers. I'd use two variables for the loop control only because I think it looks cleaner (ikr I've gotta be weird for that :P): Code:
for (int i = 0, j = stringholder1.length - 1; j >= 0; ++i, --j) |
| All times are GMT +1. The time now is 12:55 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.