Probability of obtaining pairs from two arrays such that element from the first array is smaller than that of the second array

  import java.util.*;  class GFG {                  static double probability(int[] arr1,                              int[] arr2)    {                int N = arr1.length;                  int M = arr2.length;                  double res = 0;                          Arrays.sort(arr2);                  for (int i = 0; i < N; i++) {                                                  int y = countGreater(                arr2, arr1[i]);                          res += y;        }                          res = (double)res / (double)(N * M);                  return res;    }                  static int countGreater(int[] arr,                            int k)    {        int n = arr.length;        int l = 0;        int r = n - 1;                                  int leftGreater = n;                          while (l k) {                                  leftGreater = m;                                  r = m - 1;            }                                                  else                l = m + 1;        }                          return (n - leftGreater);    }          public static void main(String[] args)    {        int[] arr1 = { 5, 2, 6, 1 };        int[] arr2 = { 1, 6, 10, 1 };        System.out.println(            probability(arr1, arr2));    }}