Print elements in an array that are in odd positions.

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram


					import java.util.Scanner;
public class ElementsInOddPositions
    public static void main(String[] args)
        /* Initialize array */  
        int [] arr;
        int n=0,i=0,j=0,count=0;
        Scanner sc = new Scanner(;    
        System.out.println("Enter a number of elements in the array");   
        n = sc.nextInt(); 
        arr=new int[n];
        System.out.println("Enter numbers in array");
        for(i=0;i< n;i++)
       /* printing elements of an array in odd positions */
        System.out.println("Elements of an array in odd positions");
        for(i=0;i< n;i++)
                System.out.print(arr[i]+"   ");

Coding Store

10-minute Stress-Buster Games

Leave a Reply

Your email address will not be published. Required fields are marked *