Results 1 to 2 of 2
  1. #1
    kraigballa is offline Senior Member
    Join Date
    Oct 2011
    Posts
    115
    Rep Power
    0

    Default ArrayList Question

    How would I go through an ArrayList: {7, 5, 4, 4, 3, 3, 2, 2} and try to get all the possible sums of 8 before printing the values left over that won't/can't add up to 8?

    For instance,
    Java Code:
    5 + 3 = 8
    2 + 4 + 2 = 8
    3 + 4 = 7 //Doesn't add up to 8, and the others have already been used
    7 = 7 //No index value plus this index value adds up to 8
    All indices must be used and only once. There will be more than one possibility but I want to have the fewest number of lines output.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,563
    Blog Entries
    7
    Rep Power
    21

    Default Re: ArrayList Question

    I posted a full solution in this thread; your problem is a variation on the same theme.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. ArrayList and .contains() question
    By Dark in forum New To Java
    Replies: 4
    Last Post: 07-08-2011, 09:34 PM
  2. Question about arraylist
    By Metastar in forum New To Java
    Replies: 7
    Last Post: 10-01-2010, 11:53 PM
  3. ArrayList question
    By spatel14 in forum New To Java
    Replies: 4
    Last Post: 07-07-2010, 10:02 PM
  4. Beginner question about ArrayList
    By kesi in forum New To Java
    Replies: 3
    Last Post: 09-19-2009, 11:30 PM
  5. arraylist question
    By lisa.lipsky in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 09-16-2009, 11:07 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
  •