Results 1 to 3 of 3
  1. #1
    louboulos is offline Member
    Join Date
    Mar 2011
    Posts
    25
    Rep Power
    0

    Default 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");
          }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default 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!

  3. #3
    Join Date
    May 2012
    Posts
    18
    Rep Power
    0

Similar Threads

  1. removing duplicate numbers from an array
    By ozzyman in forum New To Java
    Replies: 1
    Last Post: 03-14-2011, 08:22 PM
  2. Array Help - Finding and replacing duplicate cells
    By javaman1 in forum New To Java
    Replies: 5
    Last Post: 02-05-2011, 05:06 PM
  3. How to detect duplicate values in an Array?
    By maz09 in forum New To Java
    Replies: 1
    Last Post: 04-08-2010, 07:58 AM
  4. Error if array contains duplicate integers
    By lithium002 in forum New To Java
    Replies: 4
    Last Post: 12-05-2009, 08:58 AM
  5. Counting Duplicate Variables in an Array
    By Npcomplete in forum New To Java
    Replies: 2
    Last Post: 10-24-2008, 07:33 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
  •