471,852 Members | 836 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,852 software developers and data experts.

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 15194
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
reply views Thread by YellowAndGreen | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.