Finding the median value of an array?

后端 未结 9 1312
伪装坚强ぢ
伪装坚强ぢ 2020-12-03 14:58

I was wondering if it was possible to find the median value of an array? For example, suppose I have an array of size nine. Would it possible to find the middle slot of this

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 15:27

    In java :

    int middleSlot = youArray.length/2;
    yourArray[middleSlot];
    

    or

    yourArray[yourArray.length/2];
    

    in one line.

    That's possible because in java arrays have a fixed size.

    Note : 3/2 == 1


    Resources :

    • Java tutorial - Arrays

提交回复
热议问题