Java Program to print the elements of an array present on even position
Example:
Input: arr[] = { 2, 3, 7, 4, 8, 9, 2 };
Output: 3 4 9
Approach
Java
public class PrintOddPosition {public static void main(String[] args) {int arr[] = { 2, 3, 7, 4, 8, 9, 2 };for (int i = 1; i < arr.length; i = i + 2) {System.out.print(arr[i] + " ");}}}
No comments:
Post a Comment