Results 1 to 3 of 3
  1. #1
    knightsb78 is offline Member
    Join Date
    Aug 2012
    Rep Power

    Default Frustrating issue with Arrays

    Hey everyone!

    Fairly new to Java and have been struggling with some of the array use issues.

    I have 2 arrays the size of which is set by a SIZE variable:

    2 Dimensional

    Array 1: UserID[]
    Array 2 TransAmount[]

    Now I can loop through and printout the contents of these using a standard IF loop.

    What i'm having trouble with is looping through and printing out the number of transactions for each unique UserID WITHOUT using a sort/list function and without altering the data structure.

    What i've pretty much done to date is:

    Java Code:
        	  System.out.print(", ");
    I would then try to setup a seperate For loop with a nested IF statement to basically increment a count value when comparing the previous userID with the next. and then print out the value etc. The problem is that this doesnt work for an unordered list where the userIDS appear multiple times. It also ends up just looping around and printing out every userid with the count.

    Anyway, a little help or pointer in the right direction would be appreciated. Its definitely an issue with my logic for the loop so id appreciate some advice.

    Would be so simple if i could sort the list etc.


  2. #2
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Rep Power

    Default Re: Frustrating issue with Arrays

    I am not sure if I understand you correctly on what you want to do on your second loop but you might want to look at this.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: Frustrating issue with Arrays

    Quote Originally Posted by knightsb78 View Post
    without altering the data structure.
    What data structure? All I can see are two arrays and you want to keep them in 'parallel', i.e. A[n] should correspond with B[n] for all posssible values of n.

    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. What's the most frustrating thing about JAVA?
    By conopoly in forum New To Java
    Replies: 17
    Last Post: 06-30-2011, 06:37 PM
  2. Simple but frustrating error
    By JoeHill in forum New To Java
    Replies: 10
    Last Post: 06-02-2011, 09:28 AM
  3. very frustrating.. recursive
    By Yakg in forum New To Java
    Replies: 5
    Last Post: 01-06-2011, 10:25 PM
  4. get index from an array (very frustrating)
    By Yakg in forum New To Java
    Replies: 4
    Last Post: 12-06-2010, 06:26 PM
  5. Please help setting up Tomcat. Very frustrating.
    By wombatvvv in forum JavaServer Pages (JSP) and JSTL
    Replies: 5
    Last Post: 09-12-2010, 05:56 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