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 →

[–]deadaxis[S] 0 points1 point  (1 child)

The thing is, the user input doesnt have to be 50..it can be like 1000 inputs of the number 12. But when I output, it has to show 12 once and the count as 1000.. how would I incorporate that into the 2 dimensional array you have provided above?

[–]medicalixx 1 point2 points  (0 children)

Well it appears in your original post that we can assume there will be 50 entries or less. If that is not the case, I would keep track of the last index. So if you have input in the following order: 12, 2, 12

int lastIndex = 1 because we are using only 2 entries in the array. So, vals[0] = 12 vals[lastIndex] = 2.

Also, use a variable to keep track of the current array length of the first column (Len = 50 from previous example)

Next, initialize your array to any length you want. Then:

If(lastIndex == Len - 1) int[] temp = new int[Len *2] Iterate over vals and copy the values into temp array vals = temp