public class PrintEvenPositionElements {
public static void main(String[] args) {
// Initialize the array
int[] arr = {10, 20, 30, 40, 50, 60, 70, 80};
// Iterate over the array and print the elements present on even positions
System.out.print("Elements on even positions: ");
for(int i = 1; i < arr.length; i += 2) {
System.out.print(arr[i] + " ");
}
}
}
Elements on even positions:
20 40 60 80
arr
with some values. We have then used a for
loop to iterate over the array and print the elements present on even positions. System.out.print()
statement.