Home >>Java Programs >Java Program to print the elements of an array present on odd position
In this example, we will create a java program to print the elements of the array which are present in odd positions. This can be done by looping through the array and printing the elements of an array by incrementing i by 2 till the end of the array.
Algorithm
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 odd position: ");
for (int i = 0; i < arr.length; i = i+2)
{
System.out.println(arr[i]);
}
}
}