Other 2015 FR Questions FR other years Be Prepared Home
A-1
Part (a)
  public static int arraySum(int[] arr)
  {
    int sum = 0;
    for (int x : arr)
      sum += x;
    return sum;
  }


Part (b)
  public static int[] rowSums(int[][] arr2D)
  {
    int[] sums = new int[arr2D.length];
    for (int k = 0; k < sums.length; k++)
      sums[k] = arraySum(arr2D[k]);

    return sums;
  }


Part (c)
  public static boolean isDiverse(int[][] arr2D)
  {
    int[] sums = rowSums(arr2D);
    for (int k = 1; k < sums.length; k++)
      for (int j = 0; j < k; j++)
        if (sums[k] == sums[j])
          return false;

    return true;
  }

Other 2015 FR Questions | Back to Contents

Copyright © 2015 by Skylight Publishing
support@skylit.com