Accept n elements from keyboard in array in java

Write a java program to accept n elements from keyboard and find the number of even elements.

package array;

import java.util.*;
public class printeven
{
    public static void main(String args[])
    {
        Scanner s=new Scanner(System.in);
        int size,i;
        System.out.println("enter size::");
        size=s.nextInt();
        int a[]=new int[size];
        System.out.println("enter array elements::");
        for(i=0;i<size;i++)
        {
            a[i]=s.nextInt();
        }
        for(i=0;i<size;i++)
        {
            if(a[i]%2==0)
            {
                System.out.println("element is::"+a[i]);
            }
        }
    }
}

Leave a Reply

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