+ 1

How can I get the even index of an array?

So, I have to write a program where I have two options: to generate array of 10 random numbers, or to input the numbers from keyboard. Then I have to find the maximum of the elements with even index. Also, I would like to know how to find the elements with odd index. Thanks in advance!

12th Jan 2018, 12:30 AM
Winter Soldier
Winter Soldier - avatar
2 odpowiedzi
+ 5
max=arr[0]; for(int i=2;i<arr.length;a+=2){ if(arr[i]>max) max=arr[i]; } alert(max);
12th Jan 2018, 12:56 AM
Hasan Jafarov
Hasan Jafarov - avatar
+ 2
I wrote the same way, but without the "a+=2" part, so it's used to get the even index..wow.. Thank you so much!
12th Jan 2018, 1:03 AM
Winter Soldier
Winter Soldier - avatar