I'm trying to find the sum of some elements of a Java array. This array has 5 elements and if three of its elements have the same value I want the sum to be
sum += numrat[i];
Firstly I order them in ascending order. Then put the if condition. When I try to execute this an error occurs in the line of if condition.
Can someone please show me how to make this control of the elements if three of them have the same value? This is my code:
public int katerNjesoj()
{
int[] numrat=new int[zar.length];
for(int i=0;i<zar.length;i++)
numrat[i]=zar[i].getValue();
int sum=0;
for(int i=0;i<zar.length;i++)
{
if(numrat[1]==numrat[2]==numrat[3]|| numrat[2]==numrat[3]==numrat[4]||numrat[3]==numrat[4]==numrat[5] )
sum+=numrat[i];
}
return sum;
}