+ 3
Can someone help me pls?
Fill in the blanks (ā¦) to calculate the sum of all elements in the array arr using a for-each loop: int res = 0; ā¦ (int el ā¦ arr) { res += ā¦ } I canāt find out the answer for the second blank after āint elā First blank is āforā last blank is āelā
6 Answers
+ 1
int r = 0;
for (int n: arr){
r += n;
}
sout(r) // sum of all elements.
+ 1
Thank you :)
0
Using Recursion find celestial celebration planner
0
I Need answer
0
if you use a recursion so:
static int recSum(int [] array, int start, int acu){
if(start >= array.length){
return acu;
} else {
int r = array[start]
acu += r;
return recSum(array, start + 1, acu);
}
}
sout(recSum(new int [] {1,2,3}, 0, 0)) //sum of all elements.