Finding the middle element(s) of an array in Java

前端 未结 7 1892
小蘑菇
小蘑菇 2021-02-14 13:03

Given an array of integers, I need to return a new array containing the middle element(s) from the original array. Specifically, the result will have one element if the length o

7条回答
  •  花落未央
    2021-02-14 14:04

    int mid = firstIndex + (lastIndex-firstIndex)/2 , will give you the mid of the array.

提交回复
热议问题