Results 1 to 3 of 3
Thread: Frustrating issue with Arrays
- 08-11-2012, 08:29 AM #1
Member
- Join Date
- Aug 2012
- Posts
- 1
- Rep Power
- 0
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:
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.Java Code:for(i=0;i<size;i++) { System.out.print(UserID[i]); System.out.print(", "); System.out.println(TransAmount[i]);
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.
Cheers
- 08-11-2012, 08:58 AM #2
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
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.
- 08-11-2012, 09:38 AM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
Re: Frustrating issue with Arrays
When people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
What's the most frustrating thing about JAVA?
By conopoly in forum New To JavaReplies: 17Last Post: 06-30-2011, 06:37 PM -
Simple but frustrating error
By JoeHill in forum New To JavaReplies: 10Last Post: 06-02-2011, 09:28 AM -
very frustrating.. recursive
By Yakg in forum New To JavaReplies: 5Last Post: 01-06-2011, 10:25 PM -
get index from an array (very frustrating)
By Yakg in forum New To JavaReplies: 4Last Post: 12-06-2010, 06:26 PM -
Please help setting up Tomcat. Very frustrating.
By wombatvvv in forum JavaServer Pages (JSP) and JSTLReplies: 5Last Post: 09-12-2010, 05:56 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks