How to print array elements present at odd 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 = 1; i < arr.length; i += 2) {
           System.out.print(arr[i] + " ");
        }
    }
}
 
 
 
 
/*
run:
 
8 1 0 6 
 
*/

 



answered Aug 2, 2021 by avibootz

Related questions

1 answer 155 views
1 answer 142 views
1 answer 217 views
1 answer 192 views
1 answer 181 views
1 answer 141 views
...