How to print array elements present at even indexes in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        int[] arr = {3, 8, 9, 1, 7, 0, 5, 6, 4}; 
             
        for (int i = 0; i < arr.length; i += 2) {
           System.out.print(arr[i] + " ");
        }
    }
}




/*
run:

3 9 7 5 4 

*/

 



answered Aug 2, 2021 by avibootz

Related questions

1 answer 173 views
1 answer 406 views
1 answer 167 views
1 answer 127 views
1 answer 113 views
1 answer 170 views
...