Home >>Java Programs >Java Program to print the elements of an array present on even position
In this program, we will create a Java program to print the element which is present on even position of an array. Even positioned element can be found by traversing the array and incrementing the value of i by 2.
Program:
public class Main
{
public static void main(String[] args)
{
int [] arr = new int [] {1, 2, 3, 4, 5, 6, 7, 8, 9};
System.out.println("Elements of given array present on even position: ");
for (int i = 1; i < arr.length; i = i+2) {
System.out.println(arr[i]);
}
}
}