Answers for "If there are an odd number of elements in the array, return the element in the middle of the array."

0

If there are an odd number of elements in the array, return the element in the middle of the array.

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 "";
}
Posted by: Guest on March-18-2020

Code answers related to "If there are an odd number of elements in the array, return the element in the middle of the array."

Code answers related to "TypeScript"

Browse Popular Code Answers by Language