编写一个泛型方法,传入任意类型数组,颠倒(反转)数组中的所有元素,返回新数组

编写一个泛型方法,传入任意类型数组,颠倒(反转)数组中的所有元素,返回新数组
package lianxi;
import java.util.Arrays;
public class shu {
public static void main(String[] args) {
Integer[] ss = {10,12,3,6,777,8,9};
System.out.println(Arrays.toString(sh(ss)));
}
public static T[] sh(T[] ss){
for(int i=0;i<=ss.length/2;i++){
for(int j=ss.length-1-i;j>=ss.length/2;j–){
T a;
a = ss[i];
ss[i] = ss[j];
ss[j] = a;
break;
}
}
return ss;
}
}

猜你喜欢

转载自blog.csdn.net/qq_40661543/article/details/113932966