hy!!!!i am trying to write a java code that returns the majority element in an array and -1 if not!!this is what i came with
public class Majority{
public static int arrMajority1(int A[]){
int n = A.length;
int c = 1;
for(int i=0;i>A.length;i++){
for(int j=i+1;j<A.length;j++)
if (A[i]==A[j])
c=c+1;
if (c>(A.length/2)){
return A[i];
}
}
return -1;
}
public static void main(String[] args){
int A[] = new int [] {50,50,100,500,1000,1500,3000,5000,7500,10000,12000,15000,17000,20000,25000,30000,35000,40000};
// int arrMajority1 = A[0];
System.out.println(" " + arrMajority1(A));
}
}