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

前端 未结 7 1889
小蘑菇
小蘑菇 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 13:41

    I was going through Java Array docs and found that. It is perfect solution to get mid of an array.

    int low = startIndexOfArray;      // 0 Normally but can be anything
    int high = endIndexOfArray - 1;       
    
    int mid = (low + high) >>> 1;
    System.out.print("Mid Value OF Array Is "+ mid);
    

提交回复
热议问题