数组的使用
普通For循环
For-Each循环
数组做方法入参
数组做返回值
package com.kuang.array; //for-each循环 public class ArrayDemo04 { public static void main(String[] args) { int[] arrays = {1, 2, 3, 4, 5}; for (int array : arrays) { System.out.println(array); } System.out.println("========"); printArray(arrays); System.out.println("========"); for (int array : reverse(arrays)) { System.out.println(array); } System.out.println("========"); printArray(reverse(arrays)); } //打印数组元素 //数组作为参数 public static void printArray(int[] arrays) { for (int i = 0; i < arrays.length; i++) { System.out.println(arrays[i]); } } //反转数组 //数组作为返回值 public static int[] reverse(int[] arrays) { int[] result = new int[arrays.length];//定义一个返回数组,数组长度等于参数数组长度 //反转的操作 for (int i = 0, j = arrays.length - 1; i < arrays.length; i++, j--) { result[j] = arrays[i]; } return result; } }
标签:Day6,each,System,int,数组,arrays,println,返回值,out From: https://www.cnblogs.com/actadams68/p/16895409.html