for-each循环
数组作为方法入参数
数组作为返回值
public class ArrayDemon4 {
public static void main(String[] args) {
int i;
int j;
int[] arrays = {1, 2, 3, 4, 5};
int[] reverse = reverse(arrays);
printArray(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 printArray(int[] arrays){
for (int i = 0;i<arrays.length;i++){
System.out.print(arrays[i]+" ");
}
}
}
网友评论