Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27
Like Tree1Likes

Thread: Help to find solution plz.

  1. #21
    hell00 is offline Member
    Join Date
    Dec 2011
    Posts
    13
    Rep Power
    0

    Default Re: Help to find solution plz.

    That is the problem. No hole means that removing items changes the index value for the following items. That is why if i run it without removing it counts properly.

    I found the solution. As Norm said it is required to change index after removing item:

    sortList.remove(j);
    j=j-1;

    With this it counts properly. It gives 12-4, 32-2, 11-1 for input 12 12 12 12 12 32 32 32 11 11. As it should be!

    Thanks friends for all the help!
    Last edited by hell00; 12-19-2011 at 12:15 AM.

  2. #22
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: Help to find solution plz.

    it counts properly.
    Are you getting the desired output now?

  3. #23
    2by4 is offline Banned
    Join Date
    Dec 2011
    Posts
    143
    Rep Power
    0

    Default Re: Help to find solution plz.

    hmmm...iterating through a loop while it is being changed makes things complicated doesn't it.

    What about the question that was put to you earlier.

    If 20 people each gave you a shopping list on 20 pieces of paper, and you only had time to buy the popular items, what would be the first thing you would do?

  4. #24
    hell00 is offline Member
    Join Date
    Dec 2011
    Posts
    13
    Rep Power
    0

    Default Re: Help to find solution plz.

    To Norm : Yes i do. Thanks!
    To 2by4:
    Go through all the papers and memorize the most popular items. I dont really understand the question.

  5. #25
    2by4 is offline Banned
    Join Date
    Dec 2011
    Posts
    143
    Rep Power
    0

    Default Re: Help to find solution plz.

    Ok. Main thing is that you have made it work. Well done.

    Another method is to arrange or sort your data first. Java has some classes that help you do this easily.

    And the very clever method, which Norm hinted at, is to use the Set interface.
    Last edited by 2by4; 12-19-2011 at 12:34 AM.

  6. #26
    hell00 is offline Member
    Join Date
    Dec 2011
    Posts
    13
    Rep Power
    0

    Default Re: Help to find solution plz.

    Yeah, it would be easer to sort it first and then for every line just check if the next line is a duplicate. No need to go on full cycle. Didnt think of that :)
    I will look into Set interface. Thanks for your help!

  7. #27
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Help to find solution plz.

    Or a Map: count them as you read them.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. I need solution for this program
    By magesh5 in forum New To Java
    Replies: 3
    Last Post: 01-11-2011, 01:53 PM
  2. Comments on my FPS solution
    By trader5050 in forum New To Java
    Replies: 1
    Last Post: 11-17-2010, 04:51 PM
  3. Please I need the solution to this
    By debobbt in forum New To Java
    Replies: 4
    Last Post: 12-18-2009, 04:34 AM
  4. solution for my project
    By shkelqa in forum AWT / Swing
    Replies: 4
    Last Post: 05-28-2008, 10:31 PM
  5. Please need solution
    By prithvi in forum New To Java
    Replies: 4
    Last Post: 04-22-2008, 01:27 PM

Posting Permissions

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