Results 1 to 2 of 2
Thread: Counting duplicates in an array
- 01-23-2013, 12:22 AM #1
Member
- Join Date
- Jan 2013
- Posts
- 1
- Rep Power
- 0
Counting duplicates in an array
It's supposed to count all of the duplicates in an array and print out how many occurrences of the value starting at whatever index, or if there are no duplicates state that. Basically:
No duplicates with value 1 beyond Index 0
There are 3 more occurrences of value 2 starting at index 1
There are 2 more occurrences of value 2 starting at index 2....
This is what I've got so far:
If anything is correct I will be very surprised, haha.Java Code:public static void main(String[] args) { int[] arr = {1, 2, 2, 3, 4, 2, 4, 3, 0, 5, 3, 2}; for(int i = 0; i<arr.length; i++){ int count = 0; for(int j = i+1; j<arr.length; j++){ if((arr[j] == arr[i]) && (i!=j)){ count++; System.out.print("There are " + count + " more occurrences of "); System.out.println(arr[i] + " starting at index " + i); } } } }
I've been through many threads on tons of different websites about this and none of it is helping. I'm really new to this (obviously) and I am really, really, really stuck, so help would be greatly appreciated. Thank you so much!Last edited by mar1; 01-23-2013 at 06:24 AM.
- 01-23-2013, 04:55 AM #2
Re: Counting duplicates in an array
Why do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Removing Duplicates in an Array
By jerseyjava in forum New To JavaReplies: 7Last Post: 02-01-2012, 07:46 PM -
Remove Duplicates in Array
By HSKrustofsky in forum New To JavaReplies: 11Last Post: 09-06-2011, 05:47 AM -
Getting rid of duplicates in my Array problem
By 'Rasta. in forum New To JavaReplies: 6Last Post: 11-20-2010, 05:51 PM -
Duplicates in String Array
By turnergirl24 in forum New To JavaReplies: 1Last Post: 11-04-2009, 11:09 PM -
FInd the no. of duplicates in an array
By singularity in forum Advanced JavaReplies: 3Last Post: 09-04-2009, 09:25 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks