WAP to print the element of an array present on even position and odd position

import java.util.*; class CT1 { public static void main(String[] args) { int i; int[] arr = new int[10]; Scanner sc = new Scanner(System.in); System.out.println("Enter 10 Numbers : "); for(i = 0; i < arr.length; i++) { arr[i] = sc.nextInt(); } System.out.println("Here are the elements present of the Even and Odd Position"); for (i = 0; i < arr.length; i += 2) { System.out.println(" Even Position (" + i + "th) index Elements of array : " + arr[i]); System.out.println("Odd Position (" + (i+1) + "th) index Elements of array : " + arr[i+1]); } } } Copy Code
Expected Output:

Enter 10 Numbers : 1 2 3 4 5 6 7 8 9 10
Here are the elements present on the Even and Odd Positions:
Even Position (0th) index Elements of array : 1
Odd Position (1st) index Elements of array : 2
Even Position (2nd) index Elements of array : 3
Odd Position (3rd) index Elements of array : 4
Even Position (4th) index Elements of array : 5
Odd Position (5th) index Elements of array : 6
Even Position (6th) index Elements of array : 7
Odd Position (7th) index Elements of array : 8
Even Position (8th) index Elements of array : 9
Odd Position (9th) index Elements of array : 10