返回数组中间值

...
package edu.xcdq.demo01.demo03;

public class ArrayAlg {

public static  T getMiddle(T[]a){
    return  a[a.length/2];
}

}
...
...
package edu.xcdq.demo01.demo03;

public class demo03 {
public static void main(String[] args) {

    String [] str = new String[]{"111","222","333","444"};
    System.out.println(ArrayAlg.getMiddle(str));
   
    Integer [] zhengshu = new Integer[]{111,222,333,444,555};
    System.out.println(ArrayAlg.getMiddle(zhengshu));
 
    Integer [] renyishuzu = new Integer[]{140,145,150,155,160};
    System.out.println(ArrayAlg.getMiddle(renyishuzu));
}

}
...

你可能感兴趣的:(返回数组中间值)