I am suppose to write a program to calculate duplicates in an array. The code works if the are two of the same number. However, there is an error if there are three or more of the same number. How do I go about it?
public class Duplicate
{
public static void main(String[] args)
{
int[] list = new int[]{1,2,3,4,5,6,7,8,8,8,9,10};
int sum = 0;
for(int count=1; count<list.length; count++)
{
if(list[count-1]==list[count])
{
sum = list[count-1] + list[count];
System.out.println("Duplicate found: " + list[count] + " " + "Sum of the duplicate value is " +sum);
}
}
}
}