0

I want to know how to increment certain indexes in an array.

int indexArrayHIS[] = new int[15];
int indexArrayFIX[] = new int[20];

indexArrayHIS[] is an array consisting out of index values: 6 9 9 17 0 19 16 1 0 7 1 18 16 8 10

I want fill indexArrayFIX[] with the number of each index instance. For example, there are 2 "9s" so at index 9 of indexArrayFIX[] I want to display a 2:

indexArrayFIX[] should output:

2 2 0 0 0 0 1 1 1 2 1 0 0 0 0 0 2 1 1 1 0

Hope this makes sense

Thanks

1 Answer 1

2

Why not just?

for (int i = 0; i < indexArrayHIS.length; i++) {
    indexArrayFIX[indexArrayHIS[i]]++;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks that seems to be on the right track. I used two for loops because of the difference in length of the arrays and I got: 40 40 0 0 0 0 20 20 20 40 20 0 0 0 0 0 40 20 20 20 0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.