+ 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“

25th Feb 2024, 1:20 PM
Lele
6 Respuestas
+ 1
int r = 0; for (int n: arr){ r += n; } sout(r) // sum of all elements.
26th Feb 2024, 5:40 AM
Carlos
+ 1
Thank you :)
26th Feb 2024, 7:02 AM
Lele
0
Using Recursion find celestial celebration planner
27th Feb 2024, 10:41 AM
Harish
Harish - avatar
0
I Need answer
27th Feb 2024, 10:41 AM
Harish
Harish - avatar
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.
27th Feb 2024, 5:41 PM
Carlos