Java Program to print the elements of an array present on odd position

Java Program to print the elements of an array present on odd position

Example:

Input: arr[] = { 2, 3, 7, 4, 8, 9, 2 };
Output: 2 7 8 2 

Approach

Java

public class PrintOddPosition {
    public static void main(String[] args) {
        int arr[] = { 2374892 };
        for (int i = 0; i < arr.length; i = i + 2) {
            System.out.print(arr[i] + " ");
        }

    }
}


No comments:

Post a Comment