Results 1 to 3 of 3
Thread: Duplicate count in array
- 05-10-2012, 04:43 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 25
- Rep Power
- 0
Duplicate count in array
Hello! I'm trying to write a code that counts how many movies a user has seen. There is file with usernames, and according to how many times the username is repeated, the counter grows by 1. in the end that is the number of movies this user saw. If the elemets of the array are not equal i've set the programm to reset the counter and continue from the last position ( to the next user that is). But there is something wrong as always..and i can't figure it out!
Thanks for your help in advance!
Here is the code:
Java Code:for(q = 0; q < x.length; q++) { for(j = 0; j < x.length; j++) { if(x[q] == x[j]) { z++; } else if(x[q] != x[j]){ q = 0; j = 0; q = q+z; j = j+z; z = 0; } } System.out.println("User " + x[q] + " saw " + z + " movies"); }
- 05-10-2012, 05:33 PM #2
Re: Duplicate count in array
What is wrong? What does this code do? Have you stepped through this with a debugger, or at least added some print statements to figure out where the flow of the program differs from what you expect? Where's your SSCCE?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 05-10-2012, 05:37 PM #3
Member
- Join Date
- May 2012
- Posts
- 18
- Rep Power
- 0
Similar Threads
-
removing duplicate numbers from an array
By ozzyman in forum New To JavaReplies: 1Last Post: 03-14-2011, 08:22 PM -
Array Help - Finding and replacing duplicate cells
By javaman1 in forum New To JavaReplies: 5Last Post: 02-05-2011, 05:06 PM -
How to detect duplicate values in an Array?
By maz09 in forum New To JavaReplies: 1Last Post: 04-08-2010, 07:58 AM -
Error if array contains duplicate integers
By lithium002 in forum New To JavaReplies: 4Last Post: 12-05-2009, 08:58 AM -
Counting Duplicate Variables in an Array
By Npcomplete in forum New To JavaReplies: 2Last Post: 10-24-2008, 07:33 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks