Write a Java program to count the number of even and odd elements in a given array

Program


public class Demo {

	public static void main(String[] args) {
	
		int x,n,evencount=0,oddcount=0;
		int marks[]= {1,2,3,4,5,6,7,8,9,10};
		n=marks.length;
		for(x=0;x<n;x++)
		{
			if(marks[x]%2==0)
			{
				evencount++;
			}
			else
			{
				oddcount++;
			}		
		}
		System.out.println("Even Array Elements "+ evencount);
		System.out.println("Odd Array Elements "+ oddcount);
	}

}

Output:

Even Array Elements 5
Odd Array Elements 5

For latest job updates join Telegram Channel: https://t.me/sateeshm

Programs