469,326 Members | 1,464 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

Count the no. of duplicates in an array

I need to find the no. of duplicates in this array. There is something wong in the loop, can anyone please look at it and point me towards right direction.

Thanks

public class duplicate {
int temp, true_count;
int ar[] = { 1, 2, 3, 4, 1 };
int count;

public void find() {
for (int i = 0; i < ar.length - 1; i++) {
temp = ar[i];
for (int j = i; j <= ar.length-1 ; j++) {

if (temp == ar[j]) {

count += 1;
}

}


}
}

public static void main(String args[]) {
duplicate dup = new duplicate();
dup.find();

System.out.println("The No of duplicates is :" + dup.count);

}

}
Sep 4 '09 #1
3 15080
r035198x
13,262 8TB
Are you in the same class with this guy?
Sep 4 '09 #2
hey thanks for the reply. It is my post there. I could not see u there. btw I am trying to do it using hashmap
Sep 4 '09 #3
r035198x
13,262 8TB
Don't cross post questions all over the forums then.
It's very confusing and annoying for people trying to help.
Sep 4 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Graham | last post: by
1 post views Thread by steve smith | last post: by
14 posts views Thread by ak | last post: by
4 posts views Thread by Mokita | last post: by
Thekid
3 posts views Thread by Thekid | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.