Alternate Elements Of Array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Alternate Elements Of Array

How to print alternate elements of an array in Kotlin. for example elements of an array are (1,2,3,4,5,6,7,8,9) then the output should be (1,3,5,7,9)

16th Sep 2022, 3:42 PM
Saneer Ahd
Saneer Ahd - avatar
2 Answers
+ 2
Hi! in the loop, go through all the elements of the array, define the even element by the formula or not, and immediately display the result on the screen. or collect the result into a second, new array. then, display it on the screen.
16th Sep 2022, 4:25 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
You print the even or odd index elements.
16th Sep 2022, 3:54 PM
Lisa
Lisa - avatar