数组函数

来源:互联网 发布:女生提气质知乎 编辑:程序博客网 时间:2024/06/05 11:10

public class ArrayVoluation {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  int[] a = { 1, 2, 3, 4, 6, 8, 9, 7, 5, 11 };
  System.out.println("原数组遍历: ");
  for (int j : a) {
   System.out.print(j + " ");
  }
  int[] newArray = count(a);
  System.out.println();
  System.out.println("新数组遍历为: ");
  for (int i : newArray) {
   System.out.print(i + " ");
  }
 }

 public static int[] count(int[] b) {
  int sum = 0;
  for (int i = 0; i < b.length; i++) {
   sum += b[i];
  }
  b[0] = sum;
  return b;
 }
}

0 0