Java Program to Print the Elements of an Array Present on Even Position Last Updated : 21 Oct, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report The task is to print all the elements that are present in even position. Consider an example, we have an array of length 6, and we need to display all the elements that are present in 2,4 and 6 positions i.e; at indices 1, 3, 5. Example: Input: [1,2,3,4,5,6] Output: 2 4 6 Input: [1,2] Output: 2 Approach:1) First take a class with the name DisplayElementAtEvenPosition.2) Then inside the main function, declare and initialize an array with values mentioned in the above example.3) Now in -order to display the values at even position we need to iterate through the array.4) For this purpose take a for-loop and iterate through the array while incrementing the value with 2 as we need the values at even position.5) Once done with the approach, compile it to get the output. Example: Java // Java Program to Print the Elements of an Array Present on // Even Position import java.io.*; import java.util.*; public class EvenPosition { public static void main(String[] args) { // declaration and initialization of array. int[] arr = new int[] { 1, 2, 3, 4, 5, 6 }; // iterating through the array using for loop for (int i = 1; i < arr.length; i = i + 2) { // print element to the console System.out.println(arr[i]); } } } Output2 4 6 Time Complexity: O(n) where n is the size of an array Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Java Program to Store Even & Odd Elements of an Array into Separate Arrays B bunnyram19 Follow Improve Article Tags : Java Java Programs Java-Array-Programs Practice Tags : Java Similar Reads Java Program to Print the Elements of an Array Present on Odd Position An array stores the collection of data of the same type. It is a fixed-size sequential collection of elements of the same type. In an array, if there are "N" elements, the array iteration starts from 0 and ends with "N-1". The odd positions in the array are those with even indexing and vice versa. E 3 min read Java Program to Print the Elements of an Array An array is a data structure that stores a collection of like-typed variables in contiguous memory allocation. Once created, the size of an array in Java cannot be changed. It's important to note that arrays in Java function differently than they do in C/C++As you see, the array of size 9 holds elem 6 min read Java Program to Return the Elements at Odd Positions in a List Given a List, the task is to return the elements at Odd positions in a list. Let's consider the following list.Clearly, we can see that elements 20, 40, 60 are at Odd Positions as the index of the list is zero-based. Now we should return these elements.Approach 1:Initialize a temporary value with ze 3 min read Java Program to Print the kth Element in the Array We need to print the element at the kth position in the given array. So we start the program by taking input from the user about the size of an array and then all the elements of that array. Now by entering the position k at which you want to print the element from the array, the program will print 2 min read Java Program to Store Even & Odd Elements of an Array into Separate Arrays Given an array with N numbers and separate those numbers into two arrays by odd numbers or even numbers. The complete operation required O(n) time complexity in the best case. For optimizing the memory uses, the first traverse through an array and calculate the total number of even and odd numbers i 2 min read First element that appears even number of times in an array Given an array, find the first element that appears even number of times in the array. It returns the element if exists otherwise returns 0. Examples: Input : arr[] = {1, 5, 4, 7, 4, 1, 5, 7, 1, 5}; Output : 4 Explanation, 4 is the first element that appears even number of times. Input : arr[] = {2, 7 min read Like