8. Program to print the elements of an array present on odd position
💡Code:
public class singledimensionarrayp4_7078 { public static void main(String[] args) { // Example array int[] numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // Print elements at odd positions of the array System.out.println("Elements at odd positions of the array:"); printOddPositionElements(numbers); } // Function to print elements at odd positions of an array private static void printOddPositionElements(int[] array) { for (int i = 0; i < array.length; i += 2) { System.out.print(array[i] + " "); } } }
📸Output :
.png)