+ 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!
2 odpowiedzi
+ 5
max=arr[0];
for(int i=2;i<arr.length;a+=2){
if(arr[i]>max)
max=arr[i];
}
alert(max);
+ 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!