Results 1 to 2 of 2
  1. #1
    motress is offline Member
    Join Date
    Dec 2009
    Rep Power

    Default Need help in calculating average value on this format ....

    00:24:c3:31:2b:e0 -93
    00:12:17:7b:33:04 -80
    00:1f:27:55:f7:70 -70
    00:1e:13:ee:3e:40 -85
    00:24:c3:31:b8:80 -91
    00:90:4c:60:04:02 -94
    00:1b:0d:d6:6d:50 -70
    00:1a:a2:dc:a0:60 -86
    00:1e:c1:4c:c5:ce -94
    00:24:c3:31:b8:80 -91
    00:1e:c1:4c:c5:ce -94
    00:1a:a2:dc:a0:60 -91

    The above is part of my .txt file, is there any method to calculate the average value for each ID ?
    The first part is ID, second is value.
    (Note: There are repeated same ID, so how to get those value and calculate average ?

    Maybe the result will be :
    00:24:c3:31:2b:e0 average : -88
    00:12:17:7b:33:04 average : -90

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Rep Power


    well, average is sum of all items divided by the total number of items.
    perhaps where the first part is the 'key' in a hashtable, of lists,

    Java Code:
    Map<String, List<Integer>> itemsMap;
    Where you read each line into the elements of this map of lists,
    when you are done there will be exactly as many entries in the map as there are unique items.
    and the entry for the map (the list, will contain as many numbers as there were found in the input set. so that lends to computing the average.

Similar Threads

  1. how to convert one format to another format
    By mahipal_reddy621 in forum New To Java
    Replies: 1
    Last Post: 12-02-2008, 11:21 AM
  2. Test score average
    By ryn21 in forum New To Java
    Replies: 11
    Last Post: 10-17-2008, 06:49 AM
  3. Calculate Average
    By sthack99 in forum New To Java
    Replies: 4
    Last Post: 06-13-2008, 12:09 PM
  4. sum,product,average program
    By chitwood in forum New To Java
    Replies: 7
    Last Post: 01-24-2008, 06:18 AM
  5. working out wrong average
    By gemtez in forum New To Java
    Replies: 4
    Last Post: 12-12-2007, 09:35 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