Majority element in an array
<pre><code>public class rough{
 public static int arrMajority1(int A[]){
  int n = A.length;
  int c = 1;
  for(int i=0;i&gt;A.length;i++){

    for(int j=i+1;j&lt;A.length;j++)
     if (A[i]==A[j])
      c=c+1;
      if (c&gt;(A.length/2)){
      return A[i];
      }
     }
     return -1;
    }
    public static void main(String[] args){
     int A[] = new int [] {5,5,8,7,5};
    // int arrMajority1 = A[0];
     System.out.println(" " + arrMajority1(A));
    }
}
</code></pre>

<p>A majority element in an array A of size N is an element that appears more than N/2 times. For example (3,3,4,2,4,4,2,4,4) has a majority element (4), whereas the array (3,3,4,2,4,4,2,4) does not have majority element.</p>
