1. Member
Join Date
Jul 2011
Posts
1
Rep Power
0

## Count occurrence.

Suppose I have to enter 10 numbers. Now how can I count the occurrence of each number in my input? using array.
For example, if I enter 3 4 2 3 3 4 5 7 9 9. The output will be sth like
3 : 3times
4 : 2times
....
I have an array to store 10numbers. Then another array to count the occurrence. But I don't know how to make it work

2. Originally Posted by sinobu
Suppose I have to enter 10 numbers. Now how can I count the occurrence of each number in my input? using array.
For example, if I enter 3 4 2 3 3 4 5 7 9 9. The output will be sth like
3 : 3times
4 : 2times
....
I have an array to store 10numbers. Then another array to count the occurrence. But I don't know how to make it work
Use a Map<Integer, Integer> where the key is one of your numbers and the associated value is the number of times that number occurred in the sequence.

kind regards,

Jos

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•