Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By JosAH

Thread: Count occurrence.

  1. #1
    sinobu is offline Member
    Join Date
    Jul 2011
    Posts
    1
    Rep Power
    0

    Default 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
    I only self-study java for 3weeks, so please help.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by sinobu View Post
    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
    I only self-study java for 3weeks, so please help.
    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
    acmohan likes this.
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Count down
    By tj_wolf2 in forum New To Java
    Replies: 8
    Last Post: 03-14-2011, 05:07 PM
  2. Replies: 0
    Last Post: 12-06-2010, 03:36 PM
  3. Words occurrence counter for any web page
    By Dodo in forum New To Java
    Replies: 11
    Last Post: 11-10-2009, 02:16 AM
  4. Regex Pattern/Matcher - Print only one occurrence!
    By racha0601 in forum Advanced Java
    Replies: 3
    Last Post: 04-06-2009, 05:05 PM
  5. Getting row count
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-11-2008, 08:49 AM

Posting Permissions

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