Advertisement
advictoriam

Untitled

Jan 16th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. public class ArrayOps
  2. {
  3.    /**
  4.       This method accepts and integer array as a parameter, and then
  5.       returns the "middle" value of the array.
  6.       For an array of odd length, this would be the actual middle value.
  7.       For an array of even length, there are TWO middle values, so only
  8.       the first of the two values is returned.
  9.       @param values, an array of integers
  10.       @ return, the "middle" element of the array
  11.    */
  12.    public static int middleArray(int values[])
  13.    {
  14.       return values[(values.length%2 != 0) ? values.length/2 : values.length/2 - 1];
  15.    }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement