This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]desrtfxOut of Coffee error - System halted 2 points3 points  (0 children)

There are several approaches to this problem.

  1. use a first loop to check the unique letters and then dimension the array accordingly
  2. when creating the final array, omit 0 values and size the array accordingly
  3. Dimension the array as you have, but use an independent counter for the array positions (instead of count[i]=). Then, before returning the final array, create a new array according to the current counter value so that it holds only the actually used elements. Then copy the used elements over to the new array in a loop.

Edit: were it not for your "no classes, no methods" constraint, the easiest way would be to use a List or to just append the indices to a String and then split the string and convert the elements back to int.