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.
The chArray array which is holding your string, is only three is size. Yet, you are treating it a blen (six) is size.
EDIT --> Okay it is slightly more complicated. Basically, you ran out of the source string (at 3), but you are still checking the rest of blen, which overflows since there is no more source characters left.
Henry [ December 02, 2007: Message edited by: Henry Wong ]
Originally posted by Manisekar Chinnasami: yup i know the exception is thrown at that point ... how can i solve that ... but when i use 'AF' as input i am getting the result ... in this case, the arraylength is 2 only ...
Currently, your "for" loop checks all the ascii values in blen. This is what is causing the problem. You need to exit the "for" loop if either you run out of blen ascii characters, or characters in your source string. You are missing the second exit condition, which causes you to loop for more source characters, hence, the out of bounds exception.
You can probably solve this by adding an "if" check to see if you are out of characters, and "break" out of the loop, if you are.
BTW, the reason "AF" is working is because the blen "for" loop, and the source ends at the same time. Try "ABCDE", you will see that it won't work -- because the check for "F" will be at a point when you are out of characters.
Henry [ December 03, 2007: Message edited by: Henry Wong ]