Check out example codes for "If there are an odd number of elements in the array, return the element in the middle of the array.". It will help you in understanding the concepts better.

Code Example 1

public String middleElement(String[] array)
{
    if (array.length >=1){
        if (array.length %2 != 0){
            return array[array.length/2];
        }
        else if(array.length %2 == 0){
            return array[array.length/2];
        }
        return "";
    }
    else return "";
}

Learn ReactJs, React Native from akashmittal.com