public class Demo4 {
public static void main(String[] args) {
int [] arrays= {1,2,3,4,5};
//printArrary(arrays);
//JDK1.5,没有下标
//for (int array:arrays){
// System.out.println(array);//array代表数组的数值
int[] reverse =reverse(arrays);
printArrary(reverse);
}
//反转数组
public static int[] reverse(int[]arrays){
int[] result =new int[arrays.length];
//反转的操作
for (int i = 0,j=result.length-1; i < arrays.length; i++,j--) {
result[j]=arrays[i];
//分号代表一句话
}
return result;
}
//打印数组元素
public static void printArrary(int[] arrays){
for (int i=0;i< arrays.length;i++){
System.out.print(arrays[i]+" ");
}
}
}
标签:reverse,arrays,public,int,length,result,数组,操作,发转 From: https://www.cnblogs.com/anonymity12/p/18148697