[Java]Array作为参数传递,可以返回Array
2021-05-14 03:30
标签:static main string int array str out oop for [Java]Array作为参数传递,可以返回Array 标签:static main string int array str out oop for 原文地址:https://www.cnblogs.com/profesor/p/13125863.htmlpublic 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 i)
{
sum += arr[i];
}
//或者用下面for-each loop
// for (int n : arr)
// {
// sum += n;
// }
return sum;
}
}
上一篇:Python学习第八天_异常
文章标题:[Java]Array作为参数传递,可以返回Array
文章链接:http://soscw.com/index.php/essay/85439.html