Campbell Ritchie wrote:And how did you sort it out?
By the way: you do realise there is no such thing as a multi-dimensional array in Java™? It only supports arrays of arrays. You are dealing with an array of arrays of arrays.
And where did you get 36 from? You are printing 45 0s. You need to link the size of the “target” array to the size of the “source” array. That is why there are style recommendations (§10.3) against using numbers like 36, 3 and 5 in your code.
This sort of code cannot overrun the bounds of the array:Note that this suggestion will discard 8 values if your original String contains 44 tokens. You can of course add a final array of this sort to use those last 8, if you so wish:
1 2 3
4 5 6
7 8
I thought I did, but when I checked the arrays of arrays out, the values are wrong..
Thanks for the comments, and I did try your codes, and changed the for loop into 36 tokens (4,3,3)
and it generates the token value right (1 to 36).
But when the line 16 is unmasked, I got output like this,
Token value= 1
Token value= 3
Token value= 5
Token value= 7
Token value= 9
Token value= 11
Token value= 13
Token value= 15
Token value= 17
Token value= 19
Token value= 21
Token value= 23
Token value= 25
Token value= 27
Token value= 29
Token value= 31
Token value= 33
Token value= 35
Exception in
thread "main" java.lang.ArrayIndexOutOfBoundsException: 36
at alsClass.main(alsClass.java:245)
why would it be this??
Thanks in advance.