Q:

Define a method countEven() that takes two dimensional array and prints the number of even numbers in the array

0

Exercise 10: Define a method countEven() that takes two dimensional array and prints the number of even numbers in the array

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

//methods benefits:
//reusability
//suitable for team work
//easier to maintain and update


public class Main
{
	public static void main(String[] args) {
	    int a[][]={{3,5,1,7,5,2},{6,12,8,3,55,65}};
	    countEven(a);
	}
	
	public static void countEven(int [][]arr)
	{
	    int count_even=0;
	    for(int column=0;column<arr.length;column++)
	    {
	        for(int row=0;row<arr[column].length;row++)
	        {
	            if(arr[column][row]%2==0)
	            count_even++;
	        }
	    }
	    System.out.println("the number of even numbers is: "+count_even);
	}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now