This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
You have your loop set to $i <= Str.length, which is causing your errror in Str[$i]. Your array index will end at Str.length-1, so when $i = Str.length still goes through the loop Str[$i] will be out of bounds.
EDIT: darn, not fast enough....
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
Joined: May 10, 2009
W. Joe Smith
Joined: Feb 10, 2009
ahmad mayahi wrote:Complete code:
Also, it looks like you are assigning values to the whole array, but are printing just the first value. Not sure if that is what you are planning, just an FYI.
Joined: Mar 30, 2007
for (int $i = 0; $i <= Str.length; $i++)
as said by others the array runs from 0 to n-1
you should say $i < Str.length;
i guess this is what you wanted to do.... though $i is variable name $ doesnt make any difference to variable....$i or normal 'i' would make the same output
now the code compiles and runs fine. the error is !) we have to type cast to string 2) Array out of bound is run time error bcz you trying to asign the value to the out of index when you put the index as  you can assign only up to 0....2 because array index starts from 0 to length -1