+ 1

sum of arrays

Guys, how can I make the sum of the first element an array with the last element of another array and so on and save them in another array :(?

15th Nov 2020, 5:20 PM
Abigail Marquez Hernandez
Abigail Marquez Hernandez - avatar
5 ответов
+ 3
Use indexing [0] for the first and [-1] to get the last
15th Nov 2020, 5:31 PM
Ananiya Jemberu
Ananiya Jemberu - avatar
+ 1
Abigail Marquez Hernandez check out this code , I believe you are looking for something like this https://code.sololearn.com/cXaR4j6lDg0f/?ref=app
15th Nov 2020, 6:07 PM
George S Mulbah II
George S Mulbah II - avatar
+ 1
you only need one for loop to run from 0 to the size of the array (i) the counter for the second array should be declared outside of the array and decremented in the forloop (j) then simply calculate the values of the new array based on the indexes of the respective arrays within the loop using i & j
16th Nov 2020, 1:00 AM
Logomonic Learning
Logomonic Learning - avatar
0
Abigail Marquez Hernandez Your description is a bit obscure,plz explain a bit more or provide an example of inputs en outputs
15th Nov 2020, 7:02 PM
Mensch
Mensch - avatar
0
X= Array1[0] will give first element.. Y = Array2[Array2.length-1] will give you last element.. Add those save where you want.. Array3[i] = X+Y; Edit :Negetive index not work in java.. @Ananiya Jemberu
15th Nov 2020, 8:34 PM
Jayakrishna 🇮🇳