[Java]Array作为参数传递,可以返回Array
public class ArrayDemo { public static void main(String[] args) { int[] a = {1, -9, 34, 67, 0, 12 ,34 ,5, 6, 11}; System.out.println(Sum(a)); } static int Sum(int[] arr) { int sum = 0; for (int i = 0; i < arr.length; ++i) { sum += arr[i]; } //或者用下面for-each loop // for (int n : arr) // { // sum += n; // } return sum; } }